我正在使用 react 和 Ag Grid,我试图在我的远程网格中添加一个新的“行”,其中包含焦点和编辑,以这种方式:
const newRow = {
COD_CON: 'new',
COD_ABC: '000',
}
gridApi.updateRowData({ add: newRow, addIndex: 1 })
gridApi.setFocusedCell(1, DEFAULT_KEY_COLUMN)
gridApi.startEditingCell({
rowIndex: 1,
colKey: DEFAULT_KEY_COLUMN,
})
但我收到错误:
ag-Grid: updateRowData() only works with InMemoryRowModel and InfiniteRowModel.
所以我认为一个可能的解决方案是,用这样的 POST 添加新的空行:
const newRow = {
COD_CON: 'new',
COD_ABC: '000',
}
const add = await fetch(`${my}/${url}`, {
method: 'POST',
body: JSON.stringify(newRow),
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
})
刷新数据后,在我的网格末尾添加了新行,我想用焦点和编辑到达该行,因为我可以在本地使用gridApi.setFocusedCell(...)
和进行编辑gridApi.startEditingCell({...})
。我怎样才能做到这一点?
谢谢
编辑 1:通过@JulienD 的评论,我了解到我的问题并不清楚,我改变了它。谢谢