Tabulator: Issue on filter based on multiple fields

Created on 3 Jul 2017  路  4Comments  路  Source: olifolkerd/tabulator

I want to filter based on multiple fields but can't work. Here is only one search input field that compare with multiple fields of Tabulator and give the result set into the Tabulator grid. Any one can help me with sample code.
I'm using below code but not working.............

$("#mySearch").on("keyup", function () {
var filter = "AccountName";
$("#example-table").tabulator("setFilter", customFilter, "like", $(this).val());
});

function customFilter(data, type, value) {
    return data.AccountCode == "11776"; //must return a boolean, true if it passes the filter.
}
Question - Ask On Stack Overflow

Most helpful comment

Thanks so much. This is working properly.

Cheers

All 4 comments

Hey,

The setFilter function will override existing filters when it is called, so you can either pass multiple filters into the function as an array:

$("#example-table").tabulator("setFilter", [
    {field:"age", type:">", value:52}, //filter by age greater than 52
    {field:"height", type:"<", value:142}, //and by height less than 142
]);

or if you want to add the filters one after another you should use the addFilter function:

$("#example-table").tabulator("addFilter", "age", ">", 22);

Checkout the Filtering Data Documentation for more information.

Cheers

Oli

I have applied the following code block .... But this is working only for "AND" condition but I need for "OR" condition search. Please help me.....

$("#mySearch").on("keyup", function () {
$("#example-table").tabulator("setFilter", [
{ field: "AccountName", type: "like", value: $(this).val() },
{ field: "AccountCode", type: "like", value: $(this).val() },
]);
});

Need the filter that will match any one of the two fields or more

If you want an OR you will need to use a custom filter function:

$("#mySearch").on("keyup", function () {

    var term = $(this).val().toLowerCase().

    $("#example-table").tabulator("setFilter", function(data){
        return data.AccountName.toLowerCase().indexOf(term) > -1 || data.AccountCode.toLowerCase().indexOf(term) > -1;
    });
});

Thanks so much. This is working properly.

Cheers

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cemmons picture cemmons  路  3Comments

iBek23 picture iBek23  路  3Comments

mconnelley picture mconnelley  路  3Comments

aballeras01 picture aballeras01  路  3Comments

KES777 picture KES777  路  3Comments