Reputation: 21
I am having difficulties adding a context menu to my jqGrid within the onRightClick event. After right clicking on a cell I would like to get the rowid, iRow, and iCol values from the onRightClickRow event.
However, the problem that I am experiencing is that the first time I right click on a cell in the grid the context menu does not appear. The second time that I right click on a cell the context menu is displayed, but the rowid, iRow, and iCol values are all for the first cell that was right clicked. So the rowid, iRow, and iCol never match up with the cell that is right clicked.
For the context menu I am using jquery.contextmenu.r2.js
Here is the jqGrid code that I have.
jQuery("#list").jqGrid({
url:urlPath,
datatype:"json",
mtype:'GET',
jsonReader: {
root: function (obj) { return obj.result; },
id: dataID,
repeatitems: false,
page: function(obj) { return 1; },
total: function(obj) { return 1; },
records: function(obj) { return obj.result.length; }
},
colNames: columnNames,
colModel: columnModel,
onRightClickRow: function (rowid, iRow, iCol, e) {
jQuery("#list").contextMenu('rightClickMenu', {
bindings: {
'DisplayiRow': function(t) {
alert('DisplayiRow: ' + iRow);
},
'DisplayiCol': function(t) {
alert('DisplayiCol: ' + iRow);
}
}
})
},
scroll:1,
headertitles: true,
pager: '#pager',
shrinkToFit: false,
autowidth: true,
height: gridHeight,
sortable: true,
sortorder: 'desc',
viewsortcols:[true,'vertical', true],
viewrecords: true,
gridview: true,
loadonce: true
});
jQuery("#list").jqGrid('filterToolbar', {searchOnEnter:false,defaultSearch:'cn'});
});
HTML is
<div class="contextMenu" id="rightClickMenu" style="display:none">
<ul>
<li id="DisplayiRow">
DisplayiRow</li>
<li id="DisplayiCol">
DisplayiCol</li>
</ul>
</div>
Is there a way to add in a right click Context menu to the onRightClickRow event so that I can get the rowid, iRow, and iCol values of the cell that was clicked?
Upvotes: 2
Views: 11664
Reputation: 222017
Look at the old answer which contain the demo. I hope it will help to solve your problem. I am sure that binding of contextMenu
inside of loadComplete
is not the only solution of the problem, but it works very good.
Moreover, I recommend you to use context menu plugin from the plugins
subdirectory of the jqGrid source. It's the version which is tested with jqGrid and I see no sense to use another one.
Upvotes: 4