当 HeaderFilter 结果为零时更改搜索条件

Change search criteria when HeaderFilter results is zero

我希望搜索条件在用户使用 header 过滤搜索框进行搜索时进行调整,根据结果数量在 "equal" / "like" 搜索规则之间切换

示例 > 列 [=28= 的值为 ["a"、"b"、"ac"、"ab"] ]

如果搜索 "a",则只显示 value_search === row_value 的结果。 如果前面的条件 returns 0 行,将搜索条件更改为 row_value.includes(value_search)

因此搜索上面的示例值应该得到以下结果

Search : "a" 应该是 Results : "a" 只有

Search : "b" 应该是 Results : "b" 只有

Search : "ac" 应该是 Results : "ac" 只有

Search : "c" 应该是 Results : "ac"(因此这是一个 "like" 搜索,因为它不完全匹配任何值)

Search : "ab" 应该只是 Results : "ab" -(不是 "a" 也不是 "b" 因为 "equal" 搜索返回了结果)

我不确定这是否可行,但如果可行就太好了。到目前为止,我还无法使它正常工作。


如果下拉列表值(与 headerFilterParams: {values: true} 一起使用时)也根据用户的输入进行过滤,那就太好了。例如,如果 header 过滤器中输入了 "a",则建议应使用 "a", "ac", "ab"

您可以使用自定义 header 过滤函数来使用任何您喜欢的过滤规则,headerFilterFunc 列定义 属性 可用于此:

function customHeaderFilter(headerValue, rowValue, rowData, filterParams){
    //headerValue - the value of the header filter element
    //rowValue - the value of the column in this row
    //rowData - the data for the row being filtered
    //filterParams - params object passed to the headerFilterFuncParams property

    return rowData.name == filterParams.name && rowValue < headerValue; //must return a boolean, true if it passes the filter.
}

//column definition object in table constructor
{title:"Age", field:"age", headerFilter:"input", headerFilterPlaceholder:"Max Age", headerFilterFunc:customHeaderFilter, headerFilterFuncParams:{name:"bob"}}

查看 Filter Documentation 了解完整详情

过滤器函数本身正在执行过滤,因此不知道通过的行数。但是您可以使用 dataFiltered 回调来检查通过过滤器的行数,因为它是在行数组中传递的。

dataFiltered:function(filters, rows){
    //filters - array of filters currently applied
    //rows - array of row components that pass the filters
}

如果行数组长度为 0

,那么您可以更改 table 过滤器