jqGrid multiselect - limit the selection of the row only using the checkbox
Asked Answered
N

3

4

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.

Nomadize answered 2/10, 2011 at 16:13 Comment(0)
P
15

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.

Photographer answered 3/10, 2011 at 13:24 Comment(2)
@Oleg: Very nice, but it stops the onSelectRow being fired. Any suggestions how to keep the row selection (i.e. yellow etc.) but also only enable multi select through clicking the check box.Interdenominational
@AndrewWhite: Sorry, but I am not sure what you mean. If you return false from beforeSelectRow you stop selection and onSelectRow being not called. If you return true it will be called. So you have full control over the selection of the row. In the answer you will find demos which demonstrate how some multiselect options works.Photographer
S
4

I would like to suggest easier solution:

beforeSelectRow: function(rowid, e) { 
   return $(e.target).is('input[type=checkbox]');
},
Snider answered 14/3, 2014 at 10:37 Comment(1)
this will work if you have only one checkbox in the row. if any other column exists in the grid with checkbox and if the user clicks on it..then it will get affected too... so take care while implementing.Calibrate
B
4

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
Beat answered 27/4, 2015 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.