首页 > 解决方案 > 以编程方式设置集合类型过滤器时,浮动过滤器框不会更新

问题描述

当我使用 selectvalue API 以编程方式控制基于集合的过滤器时,浮动过滤器窗口不会更新。

如果您手动从浮动过滤器窗口中选择和取消选择,它可以正常工作。

请参阅https://plnkr.co/edit/707g7FHCPOOi26AlUpyn?p=preview

单击 API:仅过滤 John Joe Nevin 和 Kenny Egan,它将正确过滤,但 Athlete 的浮动过滤框为空。

如果您打开它旁边的漏斗,则过滤器是正确的。取消选择某些内容并选择其他内容,运动员姓名会正确显示在浮动过滤器输入框中。

我错过了什么吗?

//Code used to perform the filter.
var athleteFilterComponent = this.gridApi.getFilterInstance("athlete");
athleteFilterComponent.selectNothing();
athleteFilterComponent.selectValue("John Joe Nevin");
athleteFilterComponent.selectValue("Kenny Egan");
this.gridApi.onFilterChanged();

//Turn this option on as well.
floatingFilter='true'

标签: ag-gridag-grid-react

解决方案


这可能是 ag-grid 中的错误。
但是解决方法是使用setModel()api 。像这样的东西 -

  selectJohnAndKenny() {
    var athleteFilterComponent = this.gridApi.getFilterInstance("athlete");
    athleteFilterComponent.selectNothing();
    var model = ["John Joe Nevin", "Kenny Egan"];
    athleteFilterComponent.setModel(model);
    this.gridApi.onFilterChanged();
  }

推荐阅读