jqGrid:使用 beforeSelectRow 它禁用我的 onCellSelect 事件 [英] jqGrid: using beforeSelectRow it disables my onCellSelect event
问题描述
我在这里找到了我的问题的解决方案: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);
}
},
有什么想法吗?谢谢!
推荐答案
你应该明白beforeSelectRow
和onCellSelect
都是在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
inside of 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);代码>.您会看到,甚至 stackoverflow 上
OpenPopupWindow
的颜色也与 $.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屋!