繁体   English   中英

是否可以在 AG-Grid 中过滤多个字符串?

[英]Is it possible to filter for multiple strings in AG-Grid?

我一直在使用

myTable.api.setQuickFilter(string1);

一段时间以来取得了巨大的成功,但我希望能够同时过滤字符串 1、字符串 2 或字符串 3 并立即查看所有结果。 这可能吗? 我在 ag-grid 文档上找不到任何内容。

由于此处的自定义过滤器示例侧重于单个列,因此使用外部过滤器似乎是理想的解决方案。

您需要实现 2 种方法 - 在gridOptionsisExternalFilterPresent()doesExternalFilterPass(node)

  isExternalFilterPresent() {
    return true; // to indicate external filtering is on
  }

  doesExternalFilterPass(node) {

// filter only if searchtext is there
   if (this.searchText) {
        return Object.values(node.data).includes(this.searchText.split(' ')[0]) // 'string1'
         || Object.values(node.data).includes(this.searchText.split(' ')[1]) // 'string2'
         || Object.values(node.data).includes(this.searchText.split(' ')[2]); // 'string3'
    }
   return true;
}

// assuming this is bound to your input field
  externalFilterChanged(newValue) {
    this.searchText = newValue;
    this.gridApi.onFilterChanged(); // letting the grid know filter has changed
  }

从文档 -

isExternalFilterPresent
每次网格检测到过滤器变化时都会调用一次。 如果外部过滤处于活动状态,它应该返回 true 否则返回 false。 如果返回 true, doesExternalFilterPass()在过滤时会调用doesExternalFilterPass() ,否则不会调用doesExternalFilterPass()

外部过滤器通过
为网格中的每个行节点调用一次。 如果返回 false,则该节点将从最终集合中排除。

如果外部过滤器发生变化,则需要调用api.onFilterChanged()来告诉网格。

暂无
暂无

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

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