我在一个页面上有两个 jqgrids。这两个应该有上下文菜单。如果我有两个不同的上下文菜单,比如“myMenu1”和“myMenu2”,这是可能的。但我只想有一个上下文菜单,我想将它用于两个网格,实际上我从 oleg 的链接中获取了参考。请建议我怎样才能实现?
<div class="contextMenu" id="myMenu1" style="display:none">
<ul style="width: 200px">
<li id="edit">
<span class="ui-icon ui-icon-pencil" style="float:left"></span>
<span style="font-size:11px; font-family:Verdana">Edit Row</span>
</li>
<li id="del">
<span class="ui-icon ui-icon-trash" style="float:left"></span>
<span style="font-size:11px; font-family:Verdana">Delete Row</span>
</li>
</ul>
</div>
我正在做的绑定如下所示。
loadComplete: function() {
$("tr.jqgrow", this).contextMenu('myMenu1', {
bindings: {
'edit': function(trigger) {
if (trigger.id && trigger.id !== lastSelection) {
grid_location.restoreRow(lastSelection);
grid_location.editRow(trigger.id, true);
lastSelection = trigger.id;
}
},
'del': function(trigger) {
if ($('#del').hasClass('ui-state-disabled') === false) {
// disabled item can do be choosed
if (trigger.id && trigger.id !== lastSelection) {
grid_location.restoreRow(lastSelection);
//grid.editRow(trigger.id, true);
//lastSelection = trigger.id;
}
grid_location.delGridRow(trigger.id, delSettings);
}
}
},
onContextMenu: function(event/*, menu*/) {
var rowId = $(event.target).closest("tr.jqgrow").attr("id");
//grid.setSelection(rowId);
return true;
}
});
}