【问题标题】:Ag-grid text filter for filtering across an entire array of strings用于过滤整个字符串数组的 Ag-grid 文本过滤器
【发布时间】:2019-04-30 01:33:06
【问题描述】:
  • 我正在使用带有多个选项的 Angular 材质选择。
  • 每次选择或取消选择一个选项时,我都会调用一个选项 过滤表中的数据并仅显示那些 已选中。

这是 mat-select 的代码。

<mat-form-field>
<mat-select placeholder="RequestID" id = "filter-check-box" multiple>
    <mat-option (onSelectionChange) = "RequestIDCheckboxFilter($event, RequestID)" 
 *ngFor="let RequestID of RequestIDArray" [value]="RequestID">{{RequestID}}</mat-option>
</mat-select>

  • 这是 RequestIDArray 的定义:RequestIDArray: string[] = ['REQ001', 'REQ002', 'REQ003', 'REQ004'];

这就是RequestIDCheckboxFilter函数的定义。 ReqIDFilter 是我存储当前检查的值的数组。 :

RequestIDCheckboxFilter(event, text: string) {
  var CheckboxFilterComponent = this.gridApi.getFilterInstance("requestID");
  if(event.isUserInput) {
    var index = this.ReqIDFilter.indexOf(text);
    if(index == -1) {
      this.ReqIDFilter.push(text);
    } 
    else {
      this.ReqIDFilter.splice(index, 1);
    }
  }

  for(var i = 0; i < this.ReqIDFilter.length; i++) {
    CheckboxFilterComponent.setModel({
      type: "equals",
      filter: this.ReqIDFilter[i]
    })
  }

  this.gridApi.onFilterChanged();
}

执行此操作时,即使选择了多个选项,我也只能看到其中一行。比如说,如果选择了 REQ001 和 REQ002,则只有 REQ001 所在的行可见。我也尝试在 setModel 中使用 for 循环,但这会出错。有什么方法可以过滤表格中的所有值吗?

编辑:我使用的是社区版的 ag-grid。

【问题讨论】:

  • 您使用的是社区版还是企业版的 ag-grid?
  • 社区版。我会在我的问题中更新它。

标签: angular angular-material ag-grid


【解决方案1】:

我认为text filter 无法做到这一点。 在您的循环中,每次迭代都会覆盖过滤器模型。

另见ag-grid gridApi.setFilterModel() model with multiple conditions [angular6]

企业版有一个名为 Set Filter 的东西,可以满足您的需求。

所以我看到了以下选项

  • 买企业版(挺贵的)
  • 尝试创建自定义过滤器
  • 过滤网格的数据源,而不是直接过滤网格。

编辑:如果设置的过滤器是满足您需求的正确工具,那么您可以测试企业版的试用版。

也许Does ag-grid have an api to filter multiple checkbox values? 有帮助?

【讨论】:

    猜你喜欢
    • 2020-02-12
    • 2022-10-17
    • 2020-06-12
    • 2019-07-28
    • 2016-06-15
    • 2018-11-30
    • 2019-04-20
    • 2019-02-12
    • 2022-10-25
    相关资源
    最近更新 更多