Reputation: 13123
I am using onSelectRow
in a jqGrid
, it executes as I wish when I click with the left mouse button. When I right-click, it STILL executes; I want right-click to have its normal function (popup menu including "inspect element").
I guess I can return out of onSelectRow
, but I need to be able to detect which mouse button was clicked. How can I do that? The event is not available to onSelectRow()
, unless in a way I haven't been able to find.
I am aware there is another handler for onRightClickRowEvent
, but I also read that the onSelectRow
function still executes, so that won't help me (I don't know who it would help).
I also read about disabling the right-click handler for the library; I regard that as really bad programming, but in fact it won't even meet requirements here to maintain the right-click menu.
(There is another question on this; it first says to disable right-click, then to re-implement the option menu handling. I'm sure there's something simpler enough that we should not consider the latter. The former does not handle my case, which included leaving the right-click menu popup the way it is).
Upvotes: 1
Views: 628
Reputation: 13123
Actually, what I want to do can be done simply with the 3-argument version of onSelectRow
;
onSelectRow: function(id, status, event) {
if (event.which == 1) { // only process left mouse button clicks
// more code here...
}
This also gets rid of a problem we had in which a variable has a value set in onCellSelect
, which is not called on a right-click. We had cases where we were depending on a varaible which was undefined.
Anyway, by doing this, the right-click option menu now appears and is not immediately rendered useless by the select action.
Upvotes: 0
Reputation: 221997
The solution depend on the version of jqGrid and the fork, which you use (free jqGrid, commercial Guriddo jqGrid JS or an old jqGrid in version <=4.7). Free jqGrid fork, which I develop, supports selectOnContextMenu: false
option, which prevents the selection of rows inside of contextmenu
event (see the line of code). One can still use context menu without any problem.
Upvotes: 1
Reputation: 2984
What you're looking for is almost found in this answer here: https://stackoverflow.com/a/18085513/1819684.
Basically you need to "unselect" the selected row in the onRightClickRow
handler. However that answer shows return false
in the handler and if you do that you will prevent the context menu from showing, so just remove that line.
Upvotes: 1