Offval attribute custom checkbox formatter jqGrid
Asked Answered
G

1

2

I am writing a custom checkbox formatter and I have trouble understanding where the offval attribute is used for and what it value should be.

Especially when the value of the editoptions are set. For example editoptions: { value:"Yes:No" }

I can see that the default checkbox formatter always sets the offval to no. This api documentation says it can also be set to off. In the code I also see that the value can be set to the second value of the editoptions. In case of the example to No but this can be any provided value.

So how do I implement the offval attribute for my checkbox formatter? Thanks in advance!

Graf answered 31/1, 2013 at 10:31 Comment(0)
P
0

I don't think that you need to set any offval attribute inside of your custom checkbox formatter. jqGrid set the attribute itself if one uses edittype: "checkbox" (see the part of code). So it seems to me that you don't need to set offval neither in your custom formatter nor in custom editing control if you create it too.

By the way in the time when I posted the code of formatter: "clickableCheckbox" I had the same question as you. I didn't understood the mean of offval and I just included offval="no" in the code. :-). I don't think that it has any sense, but to be sure one have to test all of cause.

If you write your custom formatter which you use multiple times I would recommend you to use

(function ($) {
    "use strict";
    $.extend($.fn.fmatter, {
        yourFormatterName: function (cellValue, options) {
            ....
        }
    });
    $.extend($.fn.fmatter.yourFormatterName, {
        unformat: function (cellValue, options, elem) {
            ...
        }
    });
}(jQuery));

as prototype of the formatter. In the way you will register new formatter "yourFormatterName" which you can use exactly like any other predefined formatters: you need just use formatter: "yourFormatterName" instead of formatter: "checkbox" in the column definition of the corresponding column. I find this way very practical.

Principle answered 31/1, 2013 at 12:23 Comment(5)
I already use the format you provided :-). Will post mine formatter when it's finished, first need to clarify the offval attribute. I see it's also being used here github.com/tonytomov/jqGrid/blob/v4.4.4/js/…Graf
@MartijnB: You referenced the code of from form editing. The controls in the form was created by createEl function which I referenced in my answer. So if one use edittype: "checkbox" the offval will be set based on the value which return your unformat function. So I continue to think that no offval attribute are required or be used in the formatter.Principle
I beginning to believe you are right. But then I don't understand why the default checkbox formatter includes the offval.Graf
@MartijnB: I think that every program can be improved. :-) jqGrid will be permanently improved too.Principle
I let the question open for now until next week otherwise I mark this as answered by you - my current progress so far - gist.github.com/4673081Graf

© 2022 - 2024 — McMap. All rights reserved.