jqGrid:使用beforeSelectRow禁用我的onCellSelect事件 [英] jqGrid: using beforeSelectRow it disables my onCellSelect event

查看:275
本文介绍了jqGrid:使用beforeSelectRow禁用我的onCellSelect事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I found a solution for my issue here: jqGrid multiselect - limit the selection of the row only using the checkbox

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

but that cancels out my onCellSelect event. In short, I need to be able to select the rows ONLY when the user clicks on the checkbox column. The solution in the link above shows how to do that BUT I need to be able to take an action on specific cells in the grid, for instance, the code below opens a popup window when I click on column number 10:

  onCellSelect: function (rowid, iCol, cellcontent, e) {
      if (iCol == 10) {
          OpenPopupWindow(rowid); 
      }
  },

有什么想法吗?谢谢!

推荐答案

您应该了解beforeSelectRowonCellSelect都是在click事件处理程序内部处理的,该事件处理程序在网格主体上设置(请参见 jqGrid的部分源代码.此外,仅当beforeSelectRow返回true时才处理回调onCellSelect,因此仅当单击选择行时才进行处理(请参见

You should understand that both beforeSelectRow and onCellSelect are processed inside of click event handler which are set on the grid body (see the part source code of jqGrid). Moreover the callback onCellSelect will be processed only if beforeSelectRow returns true so only if the row will be selected by the click (see the lines of code).

作为解决方法,您可以做的只是将您当前的onCellSelect 中的代码移到beforeSelectRow中:

What you can do as a workaround is just moving your current code of onCellSelect inside of 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;
}

仅是普通的附加说明.我建议您将对列号的测试更改为对列名的测试:cm[iCol].name === 'myColumnName'而不是iCol === 10.这将使代码更具可维护性.另外,我建议您将函数OpenPopupWindow的名称更改为openPopupWindow. JavaScript的命名转换要求仅对构造函数使用具有第一个大写名称的函数.如果您将函数的名称选择为OpenPopupWindow,那么您将给出使用new运算符:var test = new OpenPopupWindow(rowid);的提示.您会看到,即使OpenPopupWindow的颜色在stackoverflow上也与$.jgrid.getCellIndex的颜色一样.您当前的选择类似于以下语句:

Just small common additional remarks. I would recommend you to change testing for column number to testing for the name of the column: cm[iCol].name === 'myColumnName' instead of iCol === 10. It will make the code more maintainable. Additionally I would recommend you to change the name of function OpenPopupWindow to openPopupWindow. The naming conversion of JavaScript require that one uses function with the first capital name only for constructors. If you choose the name of the function as OpenPopupWindow then you gives the tip to use it with new operator: var test = new OpenPopupWindow(rowid);. You see that even the color of OpenPopupWindow on stackoverflow is another as the color of $.jgrid.getCellIndex. Your current choice looks the same like the statement:

var theVariableHoldOnlyIntegerValues = true; // assign boolean

将功能OpenPopupWindow重命名为openPopupWindow可使颜色顺序排列.

Renaming the function OpenPopupWindow to openPopupWindow bring the colors in order.

这篇关于jqGrid:使用beforeSelectRow禁用我的onCellSelect事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆