I have an ag-grid table with a column defined as follows:
{ headerName: 'Population', field: 'properties.population', sortable: true, filter: 'agNumberColumnFilter'}
The data i receive is for population is a string with a numeric value inside, for example:
[
{
"properties": {
"state": "Alabama",
"name": "Montgomery",
"population": "199518"
}
},
{
"properties": {
"state": "Alaska",
"name": "Juneau",
"population": "32094"
}
}
]
Which means the filter won't work.
I worked around this by changing the data in the component
this.data.forEach(item => {item.properties.population= Number(item.properties.population)});
Is there another solution in the field of ag-grid to change the filter behavior in filterParams or something else to avoid this data manipulation?
I managed to solve this via valueGetter in the column def
{ headerName: 'Population',
field: 'properties.population',
sortable: true,
filter: 'agNumberColumnFilter',
valueGetter: (params) => { return parseInt(params.data.population) }
}
More information about valueGetter in ag-grid documentation: https://www.ag-grid.com/javascript-grid-value-getters/#example-getters-and-formatters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With