Vimalan Jaya Ganesh Vimalan Jaya Ganesh - 7 months ago 109
Javascript Question

jqGrid - suppress row selection on right click

In jqGrid, I want to disable row selection on right click. But, want to have the normal behavior (row selection on left click) enabled.

I tried to disable row selection on right click using the following code, but it does not have any effect,

onRightClickRow: function (rowid, iRow, iCol, e) {
return false;
}


Fiddler: https://jsfiddle.net/99x50s2s/235/

Expectation:


  • Row should not be selected or deselected (if previously selected) on right click in a jqGrid.



I am using jqGrid 4.6.0. Any suggestion will be appreciated.

Answer

You can do what this post suggests: Disable row select in jqGrid on right click

https://jsfiddle.net/99x50s2s/236/

onRightClickRow: function () {
    grid.jqGrid('resetSelection');
    return false;
}

It works, but just from playing around with it I noticed it unselects the previously selected row, which might not be ideal. If that's not a problem than this should be sufficient!

EDIT

If you want to maintain the previously selected row, you'll have to do something a little different.

https://jsfiddle.net/99x50s2s/239/

jQuery("sg1").unbind("contextmenu");

or

jQuery("#sg1").jqGrid({
    //Parameters
}).unbind("contextmenu");

This works, but disables the onRightClickRow event entirely.