Search code examples
node.jsnpmtabulator

Filter for keywords with either or


I would like to filter my tabulator table for multiple criteria (documentation http://tabulator.info/docs/4.5/filter#search-data) and created the following function for that:

function concepts() {
  table.setFilter("type", "like", "keyword1");
  table.setFilter("type", "like", "keyword2");
  table.setFilter("type", "like", "keyword3");
}

When I run the function, tabulator only display rows that match the last row of my filter table.setFilter("type", "like", "keyword3"); and the search for the other key words is disregarded. Is there a way to have tabulator display rows that contain either keyword1, keyword2 or keyword3?


Solution

  • Only the last call of setFilter is actually taken into account, that's why the firsts keywords are not taken into account.

    If you are sure that the the data will match one the three keywords, you can use Array In.

    table.setFilter("type", "in", ["keyword1", "keyword2", "keyword3"]);
    

    In your example, it looks like you want to use the "like" type. In that case, you should define 3 filters in an array of object like below.

    table.setFilter([
      {"field": "type", "type": "like", "value": "keyword1"},
      {"field": "type", "type": "like", "value": "keyword2"},
      {"field": "type", "type": "like", "value": "keyword3"},
    ]);
    

    Both solutions have been taken from the documentation you've linked:

    http://tabulator.info/docs/4.5/filter (In Array and Applying Multiple Filters sections)