gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:47:56 24 4
gpt4 key购买 nike

我一直在使用

myTable.api.setQuickFilter(string1);

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

最佳答案

自自定义过滤器示例 here关注单个列,使用 External filter似乎是理想的解决方案。

您需要实现 2 个方法 - 在 gridOptions 上:isExternalFilterPresent()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
is called exactly once every time the grid senses a filter change. It should return true if external filtering is active or false otherwise. If you return true, doesExternalFilterPass() will be called while filtering, otherwise doesExternalFilterPass() will not be called.

doesExternalFilterPass
is called once for each row node in the grid. If you return false, the node will be excluded from the final set.

If the external filter changes, you need to call api.onFilterChanged() to tell the grid.

关于javascript - 是否可以在 AG-Grid 中过滤多个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39045316/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com