您没有发布任何代码来显示如何您实现了内联编辑。有许多不同的实现使用内联编辑。最典型的是
- 在行选择时开始编辑,按 Enter 保存,在丢弃先前未保存行中的更改后选择另一行
- 在行选择时开始编辑,按 Enter 保存,在静默保存前一个未保存行中的更改后选择另一行
- 双击行开始编辑,按Enter保存,选择另一行后丢弃先前未保存行中的更改
- 双击行开始编辑,按Enter保存,选择另一行后静默保存前一个未保存行的更改
- 使用具有
formatter: "actions" 的附加列
-
inlineNav 方法的使用
- ...
例如,如果您使用上述列表的第一个版本并且您不想进行任何行选择,则可以将代码从 onSelectRow 移动到 beforeSelectRow。
The demo 从可能的实现中演示一个:
beforeSelectRow: function (rowid) {
var $this = $(this),
editingRowId = $this.jqGrid("getGridParam", "editingRowId"),
setEditingRowId = function (newId) {
$this.jqGrid("setGridParam", {editingRowId: newId});
};
if (rowid !== editingRowId) {
if (editingRowId !== undefined) {
$this.jqGrid("restoreRow", editingRowId);
}
$this.jqGrid("editRow", rowid, {
keys: true,
oneditfunc: function (id) {
setEditingRowId(id);
},
aftersavefunc: function () {
setEditingRowId();
},
afterrestorefunc: function () {
setEditingRowId();
}
});
}
return false;
}
UPDATED:如果要使用单元格编辑模式,相应的实现会比较困难。不过,您可能应该主要遵循the answer 的想法。 The demo 演示您需要的部分代码。它不使用任何键盘绑定。
beforeSelectRow: function (rowid, e) {
var $this = $(this),
$td = $(e.target).closest("td"),
$tr = $td.closest("tr.jqgrow"),
iRow, iCol;
if ($tr.length > 0) {
iRow = $tr[0].rowIndex;
iCol = $.jgrid.getCellIndex($td[0]);
$this.jqGrid('setGridParam', {cellEdit: true});
$this.jqGrid('editCell', iRow, iCol, true);
$this.jqGrid('setGridParam', {cellEdit: false});
}
return false;
}