【问题标题】:jqGrid - disable individual inline checkbox?jqGrid - 禁用单个内联复选框?
【发布时间】:2015-04-12 12:27:25
【问题描述】:

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

...格式化程序:“复选框”,编辑类型:“复选框”,格式选项:{禁用:假}

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

这可能吗?

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

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    我建议您使用custom formatter 或像the answerthis one 中描述的那样注册您的自定义格式化程序,然后调用原始自定义格式化程序inside of

    (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);
    }
    

    在哪里

    【讨论】:

    • 你好@Oleg 我只是尝试做一些小的改动。这似乎不再起作用了。也许 free-jqGrid 的版本发生了一些变化。你有空的时候可以看看吗?谢谢。
    • @DipenShah:你最好分享你尝试过的代码......无论如何我为你创建了演示jsfiddle.net/OlegKi/wugfty1o,我使用了我在答案和格式化程序中包含的确切代码formatter: "yourFormatterName" 工作。
    • 非常感谢@Oleg。我有一个简单的误解,并在我的代码中犯了一个简单的错字,我通过查看你的演示来修复它。你是很大的帮助。再次感谢。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      相关资源
      最近更新 更多