最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ag-Grid RowClassRule not updating after using updateRowData - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Mar 12, 2020 at 12:29 georgeawg 49k13 gold badges77 silver badges98 bronze badges asked Mar 12, 2020 at 12:07 Radical_ActivityRadical_Activity 2,73811 gold badges45 silver badges80 bronze badges 2
  • 1 have you implemented getRowNodeId method for your grid? – Paritosh Commented Mar 13, 2020 at 10:43
  • 2 Did you try api.refreshCells() or api.redrawRows(). "Your preference should be to use refreshCells() over redrawRows()" - ag grid – Rishanthakumar Commented Mar 25, 2020 at 15:44
Add a ment  | 

1 Answer 1

Reset to default 9

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

发布评论

评论列表(0)

  1. 暂无评论