如何删除使用“或”比较器创建的复杂过滤器? 删除所有过滤器删除一个复杂的过滤器

问题描述

如何使用removeFilter摆脱复杂的过滤器(如本文档中的示例所示)?

http://tabulator.info/docs/4.7/filter#func-complex

下面的示例应用了一个过滤器,该过滤器将允许年龄大于52 AND(或者高度小于142或名称为steve的行)通过

table.setFilter([
    {field:"age",type:">",value:52},//filter by age greater than 52
    [
        {field:"height",type:"<",value:142},//with a height of less than 142
        {field:"name",type:"=",value:"steve"},//or a name of steve
    ]
]);

解决方法

删除所有过滤器

如果要删除所有过滤器,可以调用 clearFilter 函数

table.clearFilter();

删除一个复杂的过滤器

目前无法直接从复杂的过滤器集中删除一个过滤器。在这种情况下,最好的方法是使用 getFilters 函数检索当前的过滤器列表,然后从要摆脱的阵列中拼接过滤器,然后进行设置再次过滤。

例如,如果您想摆脱上面示例中的“名称”过滤器,则:

var filters = table.getFilters();

filters[1].splice(1,1) //remove second filter from the `OR` section of the complex filter array

table.setFilters(filters);