我正在尝试使用字符串相似性算法的自定义过滤器添加到默认文本过滤器中。有什么办法吗?
class App extends Component {
constructor(props) {
super(props);
this.state = {
columnDefs: [
{
headerName: "Make",
field: "make",
sortable: true,
filter: true,
checkboxSelection: true,
},
...
],
...
}
}
}
在上面的代码中,如果我为Make
列的过滤器提供true
,则会显示默认文本过滤器的完整列表。但是如果我添加filterParams.filterOptions
如下所示
...
this.state = {
columnDefs: [
{
headerName: "Make",
field: "make",
sortable: true,
filter: "agTextColumnFilter",
filterParams: {
filterOptions: [
"similarTo",
{
displayKey: "similarTo",
displayName: "similar to",
test: function (filterValue, cellValue) {
...
return stringSimilarity > 0.8;
}
}
...]
}
}
... ]
}
筛选器列表中只有"类似"筛选器。 有没有办法将此自定义过滤器添加到默认文本过滤器中,包括contains
、not contains
、equals
、not equals
、starts with
和ends with
。
Ag网格提出了一个添加自定义过滤器的解决方案。
这些文件足以理解我们如何实施它们。
文档链接 : https://ag-grid.com/react-data-grid/filter-provided-simple/#custom-filter-options