1

I am using AG grid. TextFilter is working fine. but i want my ag grid to show rows when i search with string seperated with commas(","). Eg : when i search with "abc,def,xyz", it should give the result that rows contains abc or def or xyz.

Thanks in advance

  • Hey, please take a moment to further explain your question, like add a snippet of our config relating to the search function and/or some things you've attempted. – Mark Carpenter Jr Mar 09 '20 at 13:57
  • its a straight forward question. I need ag grid to search values that are separated by commas, – shaik imran Mar 09 '20 at 14:31
  • Does this answer your question? [Filtering Comma Separated Data](https://stackoverflow.com/questions/9734854/filtering-comma-separated-data) – Mark Carpenter Jr Mar 10 '20 at 13:11

1 Answers1

0

Look at using the textCustomComparator option, documented here: https://www.ag-grid.com/javascript-grid-filter-text/#text-custom-comparator

Here is an example of how it could be accomplished:

filterParams: {
  filterOptions: ["contains"],
  textCustomComparator: function(filter, value, filterText) {
    // get array of comma separated values
    const filterValues = filterText.split(',');
    // loop through filterValues and see if the value contains any of them
    return filterValues.some((item) => {
      return value.indexOf(item) >= 0;
    });
  }
}

Another option is to use a custom filter, which is documented here: https://www.ag-grid.com/javascript-grid-filter-custom/

Matt Nienow
  • 1,168
  • 6
  • 16
  • Matt Nienow, Thanks it is working in column filter. But i have my search field out of the grid. so i need a method to search any values in the grid – shaik imran Mar 10 '20 at 06:03
  • Ag-grid does have a way to do that, but not with multiple values: https://www.ag-grid.com/javascript-grid-filter-quick/ So I would instead recommend using: https://www.ag-grid.com/javascript-grid-filter-external/ You would have to do all the logic yourself, but I think it is the only way. – Matt Nienow Mar 10 '20 at 13:15
  • @MattNienow : I tried the same as I have the similar requirement but the textcustomcomparator never gets called for my textfilter. – user2868864 Sep 19 '22 at 19:03