我不知道你目前有什麼,但我測試了這一點,它的工作原理。既然你沒有提到你最初是如何開始編輯網格的,我已經在ready事件中手動完成了,你只需要跟蹤使用selIRow
var的當前正在編輯的行。
var selIRow = 1; //keep track of currently edited row
//initialized to 1 for testing purposes
$(document).ready(function() {
$("#jqGrid").jqGrid({
datatype: 'local',
colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
colModel: [
{ name: 'id', index: 'id', width: 60, editable: true },
{ name: 'invdate', index: 'invdate', width: 90, editable: true },
{ name: 'name', index: 'name', width: 100, editable: true },
{ name: 'amount', index: 'amount', width: 80, editable: true },
{ name: 'tax', index: 'tax', width: 80, editable: true },
{ name: 'total', index: 'total', width: 80, editable: true },
{ name: 'note', index: 'note', width: 150, editable: true,
//Place this code in the col options of the last column in your grid
// it listens for the tab button being pressed
editoptions: {
dataInit: function (elem) { $(elem).focus(function() { this.select(); }) },
dataEvents: [
{
type: 'keydown',
fn: function (e) {
var key = e.charCode || e.keyCode;
if (key == 9)//tab
{
var grid = $('#jqGrid');
//Save editing for current row
grid.jqGrid('saveRow', selIRow, false, 'clientArray');
//If at bottom of grid, create new row
if (selIRow++ == grid.getDataIDs().length) {
grid.addRowData(selIRow, {});
}
//Enter edit row for next row in grid
grid.jqGrid('editRow', selIRow, false, 'clientArray');
}
}
}
]
}
}
],
});
});
一些功勞從here的標籤事件轉到kajo的回答。
我在http://stackoverflow.com/questions/6781612/how-to-enalbe-up-down-arrow-keys-in-jqgrid-inline-ed發佈了相關的問題將代碼示例擴展爲在內聯編輯中啓用向上/向下箭頭鍵? – Andrus 2011-07-27 11:58:11