【问题标题】:ag-Grid RowClassRule not updating after using updateRowData使用 updateRowData 后 ag-Grid RowClassRule 未更新
【发布时间】:2020-03-29 02:03:25
【问题描述】:

我正在尝试通过以下方式更新 ag-Grid 行数据:

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

更新工作正常,单元格获取更新后的值。但是,Ag Grid 不会重新评估该行的类别。此外,我收到一条错误消息:

ag-Grid:找不到数据项,因为找不到对象

这是我的 rowClassRule:

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

我在这里做错了什么,如何让 ag Grid 也更新课程?我试过使用:rowNode.setData(),它工作得很好(更新单元格值+类)-但我不能使用它,因为它没有刷新过滤器,很遗憾。

【问题讨论】:

  • 您是否为您的网格实现了getRowNodeId 方法?
  • 你试过 api.refreshCells() 还是 api.redrawRows()。 “您的偏好应该是使用 refreshCells() 而不是 redrawRows()” - ag grid

标签: javascript ag-grid


【解决方案1】:

设置新的行数据后,由于您使用rowClass 功能,您必须使用api.redrawRows()

rowNode.setData() 作为 api 方法与 ag-grid 更改检测机制密切相关,会自动为您触发 api.refreshCells()。但是如果你是手动更新数据集,你需要调用api.redrawRows()来改变样式。

根据文档 -

如果您想从头开始重新创建行,请使用重绘行。这个 当您更改了仅在以下情况下使用的属性时很有用 该行是第一次创建的,例如:

  • 该行是否为 fullWidth。
  • 用于任何单元格的 cellRenderer(因为在创建单元格时指定了一次)。
  • 您想通过回调 getRowStyle() 或 getRowClass() 为行指定不同的样式。

此处为示例 - redraw nodes

【讨论】:

  • 我在 cellValueChanged 事件中使用它并且它有效。谢谢。
猜你喜欢
  • 2020-11-07
  • 2021-03-10
  • 1970-01-01
  • 2021-11-20
  • 2018-11-05
  • 2020-10-17
  • 2020-02-27
  • 2017-11-15
  • 2021-04-12
相关资源
最近更新 更多