jqGrid - 禁用单个内联复选框?

jqGrid - disable individual inline checkbox?

我有一个网格,其中一列有

... formatter: 'checkbox', edittype: 'checkbox', formatoptions: { disabled: false }

我想根据同一行的其他列切换 disabled 值。结果将是一个带有一些启用和一些禁用复选框的网格。

这可能吗?

我尝试在 formatoptions 值中放置一个函数 - formatoptions: { disabled: somefunction()} 但它只在 table 加载时被调用一次并且似乎不接受任何参数。

我以前遇到过这个问题。我没有在 formatoptions 中实现自定义函数,而是在 loadComplete 事件中循环网格的每一行,并根据另一列的值 enable/disable 复选框。检查 this

第三列中的所有复选框都基于第二 Name 列的值。

我建议您使用 custom formatter or register your custom formatter like it's described in the answer or in this one 并在 中调用原始自定义格式化程序

(function ($) {
    "use strict";
    $.extend($.fn.fmatter, {
        yourFormatterName: function (cellValue, options,
                rowObject, action) {

            // call formatter: "checkbox"
            return $.fn.fmatter.call(this, "checkbox",
                cellValue, options, rowObject, action);
        }
    });
    $.extend($.fn.fmatter.yourFormatterName, {
        unformat: function (cellValue, options, elem) {
            var cbv = (options.colModel.editoptions != null &&
                        typeof options.colModel.editoptions.value === "string") ?
                            options.colModel.editoptions.value.split(":") :
                            ["Yes","No"];
            ret = $("input", elem).is(":checked") ? cbv[0] : cbv[1];
        }
    });
}(jQuery));

在 调用原始格式化程序之前,您可以更改 options.colModel 的任何 属性:

yourFormatterName: function (cellValue, options, rowObject, action) {
    var myValue = true, // or false value DYNAMICALLY
        newOptions = $.extend(true, {
                colModel: { formatoptions: { disabled: myValue } }
            },
            options);
    return $.fn.fmatter.call(this, "checkbox", cellValue, newOptions, rowObject,
        action);
}

其中