ImmutableService 需要实现 getRowNodeId() 回调,您的行数据需要 ID

ImmutableService requires getRowNodeId() callback to be implemented, your row data need IDs

我尝试添加

[deltaRowDataMode]="true"

到我的网格并调用

this.gridApi.setRowData(this.rowData);

但是代码抛出错误

ag-Grid: ImmutableService requires getRowNodeId() callback to be implemented, your row data need IDs!

推../projects/secdo-infra-lib/node_modules/ag-grid-community/dist/lib/rowModels/clientSide/immutableService.js.ImmutableService.createTransactionForRowData @ immutableService.js:38 推../projects/secdo-infra-lib/node_modules/ag-grid-community/dist/lib/gridApi.js.GridApi.setRowData @ gridApi.js:151

在网上查了一下,我读到如果没有设置 getRowNodeId 是自动生成的,所以我不明白为什么会抛出错误。

来自docs

For the deltaRowDataMode to work, you must be providing ID's for the row nodes by implementing the getRowNodeId() callback.

The grid works out the delta changes with the following rules:

IF the ID for the new item doesn't have a corresponding item already in the grid THEN it's an 'add'.
IF the ID for the new item does have a corresponding item in the grid THEN compare the object references. If the object references are different, it's an update, otherwise it's nothing (excluded from the transaction).
IF there are items in the grid for which there are no corresponding items in the new data, THEN it's a 'remove'.

您可以通过 returns 每行的唯一 ID 的方式实现 getRowNodeId()。例如

this.getRowNodeId = function(data) {
  return data.id; //id is a field here
};

这位官方example有更多的细节