jqGrid:使用beforeSelectRow它会禁用我的onCellSelect事件

Max*_*Max 1 jquery jqgrid

我在这里找到了我的问题的解决方案: jqGrid multiselect - 仅使用复选框限制行的选择

但这取消了我的onCellSelect事件.简而言之,我需要能够在用户单击复选框列时选择行.上面链接中的解决方案显示了如何执行此操作但我需要能够对网格中的特定单元格执行操作,例如,当我单击第10列时,下面的代码会打开一个弹出窗口:

  onCellSelect: function (rowid, iCol, cellcontent, e) {
      if (iCol == 10) {
          OpenPopupWindow(rowid); 
      }
  },
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢!

Ole*_*leg 6

你应该明白,这两个beforeSelectRowonCellSelect内部处理click这些都对电网身上设置(见事件处理程序的部分源代码的jqGrid的).此外,onCellSelect仅当beforeSelectRow返回true时才会处理回调,因此仅当通过单击选择行时才会处理回调(请参阅代码).

你可以做一个变通方法只是将您当前的代码onCellSelect 里面beforeSelectRow:

beforeSelectRow: function (rowid, e) {
    var $self = $(this),
        iCol = $.jgrid.getCellIndex($(e.target).closest("td")[0]),
        cm = $self.jqGrid("getGridParam", "colModel");
    if (cm[iCol].name === "cb") {
        return true;
    }

    if (iCol === 10) {
        OpenPopupWindow(rowid);
    }

    return false;
}
Run Code Online (Sandbox Code Playgroud)

只是小小的常见附加说明.我建议您更改列号的测试以测试列的名称:cm[iCol].name === 'myColumnName'而不是iCol === 10.它将使代码更易于维护.另外我建议你将功能名称OpenPopupWindow改为openPopupWindow.JavaScript的命名转换要求使用仅具有第一个大写名称的函数用于构造函数.如果您选择该函数的名称,OpenPopupWindow那么您将提供与new操作符一起使用的提示:var test = new OpenPopupWindow(rowid);.你看到甚至OpenPopupWindowstackoverflow上的颜色是另一种颜色$.jgrid.getCellIndex.您当前的选择与声明相同:

var theVariableHoldOnlyIntegerValues = true; // assign boolean
Run Code Online (Sandbox Code Playgroud)

重命名函数OpenPopupWindowopenPopupWindow按顺序显示颜色.