当多选选项设置为 true 时,为复选框列添加自定义格式化程序

add custom formatter for checkbox column when multiselect option is set to true

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

我试图在 beforeProcessing 中访问 c​​olModel,但我还没有看到 jqgrid 自动添加的列名 'cb'。因此我无法在 'cb'.

的 colmodel 中注入格式化程序
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) 如果行的列为 Applicable=false

,复选框不应为 (visible/selectable)

jgrid版本:5.3.0

重要的是您始终在问题的文本中包含您使用(可以使用)的 jqGrid 版本。了解 jqGrid 的 fork 也很重要(free jqGrid, commercial Guriddo jqGrid 或版本 <=4.7 的旧 jqGrid)。

我开发的免费 jqGrid 分支包含一些 options/callbacks 可用于实现您的要求。

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

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

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

的行
beforeSelectRow: function (rowid) {
    var item = $(this).jqGrid("getLocalRow", rowid);

    if (item != null && !item.isApplicable) {
        return true;
    }
    return false;
},

或者,如果您使用最新版本的免费 jqGrid 之一,您可以使用 rowattr 向行添加 "jqgskipselect" class,这应该不是 select能够:

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

免费的 jqGrid 防止 select 行,其中有 class。在旧版本中,您可以使用 disabled class 来防止 selection。 "ui-state-disabled" class 如果使用 jQuery UI CSS 或者 "disabled" class 如果使用 Bootstrap CSS.