如何在Ag Grid中添加新行并刷新当前页面?

时间:2017-10-20 13:19:26

标签: reactjs ag-grid ag-grid-react

我正在使用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(...)和{{1}在本地进行编辑}。 我怎么能这样做?

由于

编辑1: 有了@ JulienD的评论,我明白我的问题不明确,我改变了。感谢

0 个答案:

没有答案