Reputation: 1044
Hy,
In my application I am using JQGrid tool for displaying the lists.
I need to show context menu on both left and right click (my client choice...). Is this possible?
For displaying the context menu on right click I am using the loadComplete function like this:
loadComplete: function () {
$("tr.jqgrow", this).contextMenu('contextMenu', {
bindings: {...},
onContextMenu: function (event) {...}
});
},
and it's working fine.
For displaying the context menu on left click I've tried the beforeSelectRow function:
beforeSelectRow: function (rowid, e){
$("tr.jqgrow", this).contextMenu('contextMenu', {
bindings: {...},
onContextMenu: function (event) {...}
});
},
but it's not working!
Does anyone have any idea how can I show the context menu at left-click on the row (or maybe selecting the row, it's the same)?
Thanks in advance,
Jeff
Upvotes: 0
Views: 2623
Reputation: 2580
Nothing from the above works on mine version of the grid if works then badly.
The best thing that worked is just to edit the \trirand\plugins\jquery.contextmenu.js file,
look for this row
$(this).bind('contextmenu', function (e)
and change or add to whatever you prefer, for example for left click do:
$(this).bind('click', function (e)
for double click do
$(this).bind('dblclick', function (e)
This worked like charm :-)
Upvotes: 0
Reputation: 222017
I suggest that you just bind click
event to the same event handler defined in the jquery.contextmenu.js
. To do this you can use the following code
var cmenu = $grid.data('events').contextmenu;
if (cmenu && cmenu.length > 0) {
$grid.click(cmenu[0].handler);
}
I use the fixed version of jquery.contextmenu.js
which now a part of jqGrid (see my suggestions here). So I bound contextMenu
not to every grid row, but to the grid element directly.
The demo shows that the above approach works. If you use additional bindings to contextmenu
event you can improve the code above to choose the correct event handler cmenu[i].handler
.
Upvotes: 1
Reputation: 69915
Try this code which is basically triggering a right click.
beforeSelectRow: function (rowid, e){
console.log(this);
console.log(rowid);
$("tr.jqgrow", this).trigger({
type: 'mousedown',
which: 3
});
}
Upvotes: 0