jqGrid multiselect - limit the selection of the row only using the checkbox

陌路散爱 提交于 2019-11-27 01:42:59

问题


Good morning, I'm working on a jqGrid that have the multiselection active.

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.


回答1:


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.

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.




回答2:


I would like to suggest easier solution:

beforeSelectRow: function(rowid, e) { 
   return $(e.target).is('input[type=checkbox]');
},



回答3:


When multiselect is set to true, clicking anywhere on a row selects that row; when multiboxonly is also set to true, the multiselection is done only when the checkbox is clicked. So the answer would be:

multiboxonly: true


来源:https://stackoverflow.com/questions/7627512/jqgrid-multiselect-limit-the-selection-of-the-row-only-using-the-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!