Aggrid 如何在不更改过滤字符串的情况下更改 rowData 后触发 forEachNodeAfterFilter

Aggrid How to trigger forEachNodeAfterFilter after rowData has changed without changing the filter string

我有一个自定义标签,用于显示筛选的行数 ("currently displaying x out of y results")。 当我更改过滤器字符串时效果很好,因为我使用

(filterChanged)="onFilterChanged($event)"

在我的 ts 文件中:

onFilterChanged() {
    let filteredRowCount = 0;
    this.gridApi.forEachNodeAfterFilter(() => {
        filteredRowCount++;
    });
    this.numberToShow = filteredRowCount;
}

(我绑定的变量是numberToShow)。

我有一个刷新按钮,可以使 this.rowData 得到更新。如果用户应用过滤器并刷新数据,我无法通过编程方式知道当前显示了多少行。

有什么建议吗?

谢谢!

您可以通过在每个列的 filterParams 中添加 newRowsAction: 'keep' 来解决它。
然后点击刷新按钮,你应该添加

if (this.gridApi.isAnyFilterPresent()) {
  this.gridApi.onFilterChanged() 
}

这应该会强制触发您的 filterChanged 逻辑

万一其他人在这里结束,agTotalAndFilteredRowCountComponent 状态栏组件可以开箱即用(企业)https://www.ag-grid.com/javascript-data-grid/status-bar/