Forum
17:47
10/08/2009
Hello Tony,
I suggest to make small bug fixes in the jquery.contextmenu.js included in jqGrid as plugin.
1) trigger variable defined in the line 21 will be never used. It can be removed.
2) parameter options from the line 91 will be never used in the body of the function display. It can be also removed.
3) parameter e from the line 112 will be also never used and can be removed.
4) The most important bug is that the variable currentTarget defined in the line 21 will be never assigned and undefined value are used in the line 114 as the second parameter of func function invocation. I suggest to include inside of the oby of $(this).bind('contextmenu', function(e) { (for example after the line 84) the assignment
You can download the modified version of the jquery.contextmenu.js file here.
After the fix one will have inside of any functions inside of bindings the parameter currentTarget assigned to the DOM element at which the context menu was opened. So instead of binding contextMenu to every row of the grid (call of $("tr.jqgrow", this).contextMenu('myMenu1', {…}) inside of loadComplete every time when grid contain will be rebuild) one will be able to call $('#list').contextMenu('myMenu1', {…}) only once. So the code coule be about the following:
grid.contextMenu('myMenu1', {
bindings: {
edit: function (trigger, currentTarget) {
var rowId = $(currentTarget).closest("tr.jqgrow").attr("id");
grid.jqGrid('editGridRow', rowId, editSettings);
},
add: function () {
grid.jqGrid('editGridRow', "new", addSettings);
},
del: function (trigger, currentTarget) {
var rowId = $(currentTarget).closest("tr.jqgrow").attr("id");
grid.jqGrid('delGridRow', rowId, delSettings);
}
},
onContextMenu: function (e) {
var rowId = $(e.target).closest("tr.jqgrow").attr("id");
if (!rowId) {
return false; // no contex menu on rows having no "jqgrow" class
}
grid.jqGrid('setSelection', rowId);
return true;
}
});
where editSettings, addSettings and delSettings can be dfined above. See the demo.
Best regards
Oleg
18:23
Moderators
30/10/2007
Thanks Oleg,
Will check this.
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
00:46
10/08/2009
Hello Tony,
The next problem in the context menu that it returns always false from the contextmenu event (see here). I suggest to make the following small modification in the code
// Check if onContextMenu() defined
var bShowContext = (!!hash[index].onContextMenu) ? hash[index].onContextMenu(e) : true;
currentTarget = e.target;
if (bShowContext) {
display(index, this, e, options);
return false;
}
});
You can find additional information in the answer.
Best regards
Oleg
Most Users Ever Online: 715
Currently Online:
35 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66