How to access a cell value when the column has been defined with ag-grid expression/value getters?

6.5k Views Asked by At

If the ag-grid column definition has been defined with a value getter or if an expression has been defined for a cell the value gets displayed fine on the grid. However I was not able to find a way to access a value in a given cell if the cell is using cell expression/value getters. Was trying to access the data through api.forEachLeafNode, but it seems even the in memory model does not have this data. The only way I found was to export the data as CSV and then parse it using getDataAsCsv(params).

Is exporting the data the only way to access value of a column in a grid with a value getter?

Why does the In Memory model not have this data to access?

1

There are 1 best solutions below

0
On

valueGetter is used during the rendering stage, it only computes when needed to render the cell. if the cell is never rendered (eg row is below what is currently visible) then the valueGetter is never executed. the result is never stored in the model, it is only passed to the cellRenderer.

so what you need to do to get the result of valueGetter is use api.getValue(colKey,rowNode)

colKey is the id of your column. this can be the column itself (if you got the column from the grid column api) or the column id. the column id is what you will probably want to use. the column id is assigned to the column in the following order 1) the colDef.colId if exists 2) the colDef.field if exists 3) generated if both colId and field are missing. so if you are using a valueGetter, you are probably not providing a field, so just provide a colId.

rowNode is the row in question. this is what you get when you use api.forEachLeafNode.

the api.getValue() method is pretty recent, i know it's in version 7 - so if missing just make sure you are v7 or above.