ag-Grid RowClassRule not updating after using updateRowData

Viewed 3055

I'm trying to update an ag-Grid row data the following way:

this.table.api.updateRowData({
    update: [response.data]
})

The updating works fine, the cells get the updated values. However, Ag Grid is not re-evaluating the class of the row. Additionally, I get an error message:

ag-Grid: could not find data item as object was not found

Here is my rowClassRule:

rowClassRules: {
    "row-disabled": function(params) {
        if (params.data.status != 1) {
            return true
        }
    }
}

What am I doing wrong here and how can I get ag Grid to update the class as well? I have tried using: rowNode.setData() which was working perfectly (updating the cell value + class) - but I can't use it because it's not refreshing the filters, unfortunately.

1 Answers

After setting the new row data, since you are using rowClass feature you have to use api.redrawRows()

rowNode.setData() being an api method is closely tied with ag-grid change detection mechanism and would automatically trigger api.refreshCells() for you. But if you are manually updating the data set, you need to invoke api.redrawRows() for styles to change.

As per docs -

Use redraw row if you want to create the row again from scratch. This is useful when you have changed a property that only gets used when the row is created for the first time such as:

  • Whether the row is fullWidth or not.
  • The cellRenderer used for any cell (as this is specified once when the cell is created).
  • You want to specify different styles for the row via the callbacks getRowStyle() or getRowClass().

Example here - redraw nodes

Related