Search code examples
javascripttabulator

How do I remove complex filters created with the "OR" comparator?


How do you use removeFilter to get rid of complex filters (like in this example from the documentation)?

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

The example below applies a filter that will let through rows with a age of greater than 52 AND (either a height of less than 142 OR with the name 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
    ]
]);

Solution

  • Remove All Filter

    If you want to remove all filters you can call the clearFilter function

    table.clearFilter();
    

    Remove One Complex Filter

    At the moment there is no way to remove one filter in a complex filter set directly. The best approach in this case would be to use the getFilters function to retrieve the current filter list, then splice the filter from the array you want to get rid off, then set the filters again.

    For example if you wanted to get rid of the "name" filter from your above example:

    var filters = table.getFilters();
    
    filters[1].splice(1,1) //remove second filter from the `OR` section of the complex filter array
    
    table.setFilters(filters);