實際上,我是能夠找到必要的(但文檔中缺少的)代碼,甚至允許這種行爲:
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');