简体   繁体   English

如何在 ag-grid 中获取过滤的行?

[英]How to get filtered rows in ag-grid?

I have an ag-Grid with filtering option.我有一个带过滤选项的ag-Grid

How to get the filtered rows (not the selected) in ag-Grid?如何在 ag-Grid 中获取过滤的行(不是选定的)?

You can use the forEachNodeAfterFilter(callback) api method for this.您可以为此使用 forEachNodeAfterFilter(callback) api 方法。

See https://www.ag-grid.com/javascript-grid-api for all available API calls, including the various forEachXXX methods.有关所有可用的 API 调用,包括各种 forEachXXX 方法,请参阅https://www.ag-grid.com/javascript-grid-api

This took me forever so I'm posting here.这花了我永远,所以我在这里张贴。 Use onFilterChanged() to access the filtered rows, or the filtered + selected rows.使用onFilterChanged()访问过滤的行,或过滤的 + 选定的行。 The event passed to onFilterChanged() can be used like so (example in Typescript React)传递给onFilterChanged()的事件可以像这样使用(Typescript React 中的示例)

onFilterChanged = ev => {
  if (ev?.api?.rowModel?.rowsToDisplay) {
    this.setState({ selectedRows: ev?.api?.rowModel?.rowsToDisplay.filter(node => node.isSelected()) });
  }
};

Building off @sean-landsman's answer, here's an example of how to use the forEachNodeAfterFilter(callback) method:根据@sean-landsman 的回答,以下是如何使用forEachNodeAfterFilter(callback)方法的示例:

    let rowData = [];
    gridApi.forEachNodeAfterFilter(node => {
      rowData.push(node.data);
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM