Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I tried to add

[deltaRowDataMode]="true"

to my grid and called

this.gridApi.setRowData(this.rowData);

but the code throws the error

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

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

Looking this up online I have read that getRowNodeId is auto generated if not set so I don't understand why the error is thrown.

like image 410
mila Avatar asked Feb 16 '19 20:02

mila


People also ask

How do I find row ID on Ag grid?

Row IDs are generated by the grid when data is supplied to the grid. The grid uses a sequence starting at 0 and incrementing by 1 to assign row IDs, so for example if there are three rows they will have IDs of 0 , 1 and 2 . The row ID does not change for a row once it is set.

How do you get row data in Ag grid?

To get the currently selected rows you can then use the grid API method getSelectedRows() to return a list of all the currently selected row data.

How do I turn off rows on Ag grid?

There is no option in the library to make a single row disabled(both visually and keyboard event based), the only way we could make a single row disabled is by using a customCellRenderer for both header and subsequent cell checkboxes, this allows full control over the checkbox.

How do you get grid options on Ag grid?

Access the Grid & Column API You can access the APIs in the following ways: Store them from the gridReady event - they'll be available via the params argument passed into the event. Provide a gridOptions object to the grid pre-creation time. Post-creation the APIs will be available on the gridOptions object.


1 Answers

From the 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'.

You can implement getRowNodeId() in a way that it returns unique ids for each row. e.g.

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

This official example has more details

like image 73
Pratik Bhat Avatar answered Sep 20 '22 22:09

Pratik Bhat