私たちはAG-Gridフォーラムに頼んだ。これを行うには簡単で清潔な方法はありませんでした。基本的には、 'Enter'が押されていることを聞くイベントをグリッドに追加し、手動でフォーカスを1行下に移動します。
「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