Here's a StackBlitz that demonstrates the issue/question: https://stackblitz.com/edit/react-s9l2kj
(this is essentially a modified version of the Example Row Class Rules code from the ag-grid website)
I have a getRowClass
function that needs to be updated when a property passed to my component changes. In the provided code example, this is passed to the Grid
component (here's a cut-down version):
const Grid = (props) => {
const getRowClass = (params) => {
var numSickDays = params.data.sickDays;
if (numSickDays > props.minDays && numSickDays <= props.maxDays) {
return 'sick-days-warning';
};
return '';
};
return (
<>
<AgGridReact
rowData={data}
columnDefs={columnDefs}
getRowClass={getRowClass}
/>
<label>Show warning when: {props.minDays} < sick days <= {props.maxDays}</label>
</>
);
}
In the StackBlitz example, updating the value in the Min days
textbox correctly causes the label to re-render, showing that the new property is correctly being passed to the grid.
Question
Why doesn't the getRowClass
function get updated? It looks to me like the AgGridReact
is caching the first value for getRowClass
that gets passed to it, rather than updating it when a new getRowClass
function is getting created - so that feels like a bug... however, I may be misunderstanding how I should be updating the getRowClass
function.