如何在 AgGrid 中动态应用过滤器?

How to apply filter dynamically in AgGrid?

我正在尝试按照 AgGrid 网站上的官方示例进行操作: https://www.ag-grid.com/javascript-grid-filter-api/#example-filter-api

使用 v20.1 我无法应用过滤器,如何

  const myFilterInstance = api.getFilterInstance('my_field');
  if (myFilterInstance ) {
    myFilterInstance .setModel({
      type: 'equals',
      filter: 'blah'
    });
    (myFilterInstance as any).applyModel();
    api.onFilterChanged();
  }

AgGrid的v20.1定义好像没有applyModel?在 v20 中动态更改过滤器的正确方法是什么?

如果您正在做 setModel,则无需调用 applyModel。只需调用 api.onFilterChanged.

  sportStartsWithS() {
    var sportsFilterComponent = this.gridApi.getFilterInstance("sport");
    sportsFilterComponent.setModel({
      type: "startsWith",
      filter: "s"
    });
    this.gridApi.onFilterChanged();
  }

参考:https://www.ag-grid.com/javascript-grid-filter-api/#example-filter-api (同link)