我们结束了在AG-Grid论坛的要求。没有简单或干净的方法来做到这一点。基本上你可以在网格中添加一个事件来监听'Enter'被按下,然后手动将焦点向下移动一行。
当'Enter'事件被触发时,您必须知道用户当前是否正在编辑,并且注意用户是否在最后一行。
gridDiv.addEventListener('keydown', function(evt) {
if(editing && evt.key === 'Enter') {
var currentCell = gridOptions.api.getFocusedCell();
var finalRowIndex = gridOptions.api.paginationGetRowCount()-1;
// If we are editing the last row in the grid, don't move to next line
if (currentCell.rowIndex === finalRowIndex) {
return;
}
gridOptions.api.stopEditing();
gridOptions.api.clearFocusedCell();
gridOptions.api.startEditingCell({
rowIndex: currentCell.rowIndex + 1,
colKey: currentCell.column.colId
});
}
});
编辑标志在网格选项中手动管理。
var editing = false;
var gridOptions = {
columnDefs: columnDefs,
rowData: students,
onCellEditingStarted: function (evt) {
editing = true;
},
onCellEditingStopped: function (evt) {
editing = false;
}
};
这里是一个工作plunker例如:
https://plnkr.co/edit/quhyS05SSVzmuDlCErZD?p=preview