【问题标题】:add custom formatter for checkbox column when multiselect option is set to true当多选选项设置为 true 时,为复选框列添加自定义格式化程序
【发布时间】:2019-08-24 21:57:49
【问题描述】:

我使用 jqgrid 作为具有 multiselect:true 属性的网格。我想根据某些行值删除某些行的复选框(禁用/不允许检查)。我想在复选框模型上添加格式化程序以删除该列上的复选框

我尝试在 beforeProcessing 中访问 c​​olModel,但我还没有看到 jqgrid 自动添加的列名“cb”。因此我不能在 colmodel 中为 'cb' 注入格式化程序。

jqGrid({
  multiselect: true,
  beforeSelectRow: function() {
     //called when tried to select one row.
     //its not called when selectAll is called.
  },
  onSelectAll: function(rowids, status) {
     //gets selected row ids when status is true
  }
})

1) 我想根据行值来操作复选框的选择。

2) 如果行的列 isApplicable=false,则复选框不应(可见/可选择)

jgrid 版本:5.3.0

【问题讨论】:

    标签: javascript jquery jqgrid


    【解决方案1】:

    务必在问题的文本中包含您使用(可以使用)的 jqGrid 的版本。了解 jqGrid 的分支也很重要(free jqGrid、商业 Guriddo jqGrid 或版本

    我开发的免费 jqGrid fork 包含一些可用于实现您的要求的选项/回调。

    首先你可以使用hasMultiselectCheckBox回调来通知jqGrid应该在哪些行(例如基于isApplicable列的内容)创建多选复选框:

    hasMultiselectCheckBox: : function (options) {
        // options is object like below
        // { rowid: rowid, iRow: irow, iCol: pos, data: item, checked: checked };
        // one can use options.data to examine the data of the current row
    
        return options.data != null && options.data.isApplicable;
    }
    

    即使该行中不存在复选框,仍然可以通过单击该行来选择该行。 (顺便说一句,您可以使用multiselectPosition: "none" 来完全没有带有多选复选框的列。)因此您应该另外添加beforeSelectRow 回调,这可以防止选择isApplicable 等于false 的行:

    beforeSelectRow: function (rowid) {
        var item = $(this).jqGrid("getLocalRow", rowid);
    
        if (item != null && !item.isApplicable) {
            return true;
        }
        return false;
    },
    

    或者,如果您使用最新版本的免费 jqGrid 之一,您可以使用 rowattr"jqgskipselect" 类添加到行中,这应该是不可选择的:

    rowattr: function (item) {
        if (!item.isApplicable) {
            return { "class": "jqgskipselect" };
        }
    },
    

    free jqGrid 防止选择具有类的行。在旧版本中,您可以使用禁用类来防止选择。在使用 jQuery UI CSS 的情况下是 "ui-state-disabled" 类或在使用 Bootstrap CSS 的情况下是 "disabled" 类。

    【讨论】:

    • 我已经试过 rowattr。但真正的问题在于 selectAll。即使我跳过 checkbox.selectAll 默认情况下会返回所有可见行。它不会跳过不适用的复选框。总是返回所有记录。 $('gridid').jqGrid('getGridParam', 'selarrrow')
    • @MayurPatil:您在问题末尾添加了您使用 commercial Guriddo jqGrid 5.3.0。它不支持hasMultiselectCheckBoxjqgskipselect。所以你在selectAll 中遇到了问题,因为使用了不支持jqgskipselect 类的fork。我写道,您可以使用禁用的类而不是 jqgskipselectui-state-disableddisabled)取决于您使用的 CSS 框架。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    相关资源
    最近更新 更多