jqGrid multiselect-仅使用复选框限制对行的选择 [英] jqGrid multiselect - limit the selection of the row only using the checkbox
问题描述
早上好,我正在开发一个具有多重选择功能的jqGrid.
Good morning, I'm working on a jqGrid that have the multiselection active.
我只需要使用multisel框来限制对行的选择,而不是单击行上的任何地方. 那是因为我需要通过单击某些单元格上的链接来执行某些操作,并且我不会更改活动的多选. 我试图设置multiboxonly属性,但这不是我所需要的. 我没有找到其他可自定义网格功能的东西.
I need to limit the selection of the row only using the multisel box, not by clicking everywhere on the row. Thats's because I need to do some action by clicking links on some cells and I won't alter the active multiselection. I tried to set the multiboxonly property, but it's not what I need. I didn't find anything else to customize this function of the grid.
推荐答案
You can control on which click the row will be selected with respect of your custom beforeSelectRow event handler. If the handler return true, the row will be selected. If you return false the row will be not selected.
beforeSelectRow
的第二个参数是事件对象,e.target 是被点击的DOM元素.您可以获取使用$(e.target).closest('td')
完成点击的单元格(<td>
).然后,您可以使用 $ .jgrid.getCellIndex 来获取单元格的索引行的insido. colModel
中的索引应指向包含复选框的"cb"列.因此,代码可能如下:
The second parameter of beforeSelectRow
is event object, e.target is the DOM element which was clicked. You can get the cell (<td>
) in which the click done with $(e.target).closest('td')
. Then you can use $.jgrid.getCellIndex to get the index of the cell insido of the row. The index in the colModel
should point to the 'cb' column which contain the checkboxes. So the code could be the following:
beforeSelectRow: function (rowid, e) {
var $myGrid = $(this),
i = $.jgrid.getCellIndex($(e.target).closest('td')[0]),
cm = $myGrid.jqGrid('getGridParam', 'colModel');
return (cm[i].name === 'cb');
}
您可以在此处看到相应的演示.
The corresponding demo you can see here.
这篇关于jqGrid multiselect-仅使用复选框限制对行的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!