Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify the RowNode.id in ag-grid

I'm posting this here because this wasted a fair bit of my time today.

I was trying to set the RowNode.id from the data in the objects I set aggrid's rowData property to. meaning, I wanted to use a property on my data model to supply the built in id field of ag-grid's row model. They mention this in the documentation but they don't explain how to do itp.

like image 803
Jason Wall Avatar asked Mar 22 '18 21:03

Jason Wall


People also ask

How do you get Rownode on Ag grid?

The easiest way to get a Row Node is by its Row ID. The ID is either provided by you using the grid callback getRowId() , or generated by the grid using an internal sequence.

How do I get cell ID on Ag grid?

You need to set [getRowNodeId] property for your ag-grid. when you set it to a function, the return value is considered as the id for the row . this. _getRowNodeId = (item: any): string => { return `${item.id}`; };

How do you set rowHeight on Ag grid?

To change the row height for the whole grid, set the property rowHeight to a positive number. For example, to set the height to 50px, do the following: const gridOptions = { rowHeight: 50, // other grid options ... } Changing the property will set a new row height for all rows, including pinned rows top and bottom.

How do I select a checkbox in Ag grid?

Header Checkbox Selection It is possible to have a checkbox in the header for selection. To configure the column to have a checkbox, set colDef. headerCheckboxSelection=true . headerCheckboxSelection can also be a function, if you want the checkbox to appear sometimes (e.g. if the column is ordered first in the grid).


1 Answers

To get ag-grid to use application assigned IDs, implement the grid callback getRowNodeId(). The callback should return back the ID for a particular piece of row data. For example, the following code snippet returns back the value of attribute 'id' for the supplied data item:

function getRowNodeId(data) {
    return data.id;
}

When providing IDs the following rules must be obeyed:

  1. IDs must be unique
  2. IDs must not change

If the attribute you are intending to use as an ID is either not unique or changes, it will cause unspecified behaviour in the grid. In other words, don't use a field that is not unique or can change.

If using Row Grouping, the grid will always assign IDs for the group level (as there is not a one-to-one mapping with application-supplied row data). The callback getRowNodeId() is only used for non-group level rows.

Here's a link to documentation

like image 153
Kiril Matev Avatar answered Oct 03 '22 16:10

Kiril Matev