1

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).

arcy
  • 12,845
  • 12
  • 58
  • 103
  • Yeah, did see that one, should have mentioned it -- it says to disable right-click entirely (which doesn't solve my problem) or essentially to re-implement the option menu. – arcy Feb 15 '18 at 20:19

3 Answers3

1

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.

gforce301
  • 2,944
  • 1
  • 19
  • 24
1

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
0

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.

arcy
  • 12,845
  • 12
  • 58
  • 103
  • **Could you write which version of jqGrid you use and from which fork of jqGrid ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7)?** Your post shows that you misunderstand what is `onSelectRow`. It's not an event handler of `click` or `contextmenu` events. The `onSelectRow` will be called **after** processing of `click` or `contextmenu` events. The row is *already selected*. `beforeSelectRow` allows to prevent selection in case of `click` event, but not in case of `contextmenu`. – Oleg Feb 15 '18 at 22:35
  • If I interpret our config directly, this jqGrid is part of jquery-ui-1.12.1. Thanks for the clarification of onSelectRow, I wish we could sit and chat for a bit so I could get a bit more definitive information instead of the endless examples of varying degress of helpfulness. – arcy Feb 16 '18 at 14:15
  • jqGrid is not a part of jQuery UI. jqGrid is jQuery plugin and require only jQuery, but it *uses* CSS framework jQuery UI (only css file and no js files of jQuery UI are required) or Bootstrap CSS depend on **the version** of jqGrid, which you use. jqGrid existed till version 4.7 and it's dead since the end of 2014. After that there are "free jqGrid" product, which can be used completely free of charge (like old jqGrid) and **commercial** product "Guriddo jqGrid JS". Which one you use (can use)? – Oleg Feb 16 '18 at 14:44
  • Can we continue in chat? – arcy Feb 16 '18 at 15:15
  • Yes, I have now some time for chatting. – Oleg Feb 16 '18 at 15:39
  • will wait here. https://chat.stackoverflow.com/rooms/165295/room-for-arcy-and-oleg – arcy Feb 16 '18 at 15:56