实际上,我是能够找到必要的(但文档中缺少的)代码,甚至允许这种行为:
jqGrid not saving inline row edits
的“restoreAfterSelect” inlineNav属性需要被设置为假允许在'onSelectRow','beforeSelectRow','ondblClickRow'或'onRightClickRow'中进行任何操作。
虽然我能够召唤一个全功能的确认对话框,当用户在编辑另一行时双击另一行(例如,你确定要结束当前会话等),我无法实现处理上下文菜单时取得同样的成功。我只尝试在右键单击绑定上下文菜单,而不是加载完成,但菜单只会在每三分之一出现,或点击。其他更多尝试失败的尝试,但我忘了他们是由于他们的巨大徒劳。
虽然我能够做到,但在用户编辑时,完全解除了上下文菜单事件/功能的绑定。如果用户尝试双击另一行或弹出上下文菜单,则会显示一条消息,告诉他们完成编辑或取消编辑/添加/删除其他行的操作。我还设置了取消按钮刷新电网无论何时,只要点击,以重新绑定上下文菜单每一行。
代码片段,如果有人发现使用它(主要问题是不知道有关,在绊脚石 'restoreAfterSelect'):
ondblClickRow: function (rowid, iRow, iCol, e) {
var row = $('#tableTask').jqGrid('getGridParam', 'selrow');
var isEditing = $("#" + row).attr("editable") === '1';
if (isEditing) {
showModal('Error', 'You are currently editing a record, please click the cancel button or complete your edits before continuing.', 'frmInsertTask');
$('#tableTask').jqGrid('setGridParam', 'savedRow', [{ 'id': row }]);
$('#tableTask').setSelection(row);
return false;
} else {
$('#tableTask_iledit').trigger('click');
return true;
}
},
beforeSelectRow: function (key, event) {
var lastSel = $(this).jqGrid('getGridParam', 'selrow');
var isEditing = $("#" + lastSel).attr("editable") === '1';
if (isEditing) {
$('#tableTask').jqGrid('setGridParam', 'savedRow', [{ 'id': lastSel }]);
$('#tableTask').setSelection(lastSel);
return false;
} else {
if (lastSel == null) { } else {
$('#tableTask').restoreRow(lastSel);
}
$('#tableTask').setSelection(key);
return true;
}
},
onRightClickRow: function (rowid, iRow, iCol, e) {
var editingRow = null;
var isEditing = false;
var ids = $('#tableTask').getDataIDs();
var row = $('#tableTask').jqGrid('getGridParam', 'selrow');
$(ids).each(function (index, element) {
isEditing = $("#" + element).attr("editable") === '1'
if (isEditing) {
editingRow = element;
return false;
}
});
if (isEditing) {
showModal('Error', 'You are currently editing a record, please click the cancel button or complete your edits before continuing.', 'frmInsertTask');
$('#tableTask').jqGrid('setGridParam', 'savedRow', [{ 'id': editingRow }]);
$('#tableTask').setSelection(editingRow);
return false;
} else {
if (editingRow == null) { } else {
$('#tableTask').restoreRow(editingRow);
}
$('#tableTask').setSelection(rowid);
return true;
}
而且,#tablename_liadd AND#的点击事件中tablename_liedit按钮:
$('#tableTask_iladd, #tableTask_iledit').bind('click', function() {
//if the context menu is visible then hide it. (for sitch where user brings up context menu, but then goes and clicks on the add/edit button.
$('#jqContextMenu').hide();
//while in edit/add mode, user should not be able to bring up the context menu until they end their current session. this context menu is re-bound once the user clicks the cancel button(refreshes the grid) or they save the data they are inputting (will result in a refresh once the transaction is completed).
$("#tableTask tr.jqgrow").unbind('contextmenu');