How to override Ag Grid QuickFilter to receive exact match results?

Viewed 396

By default Ag Grid Quick Filter function return rows that contains search string. For example if I type "30 June" in the searchbox, quick filter will also return rows that contains "30 cars were sold by 2 June" text. How can I override default behavior to receive only rows that exactly match my search string?

1 Answers

What I did was the following:

In the search itself, I removed the spaces from the search criteria: this.gridApi.setQuickFilter(event.toLowerCase().replace(" ", ""));

In each column that I wanted an exact match, I added this code in the column definition: getQuickFilterText: (params) => { return params.value && params.value.toLowerCase().replace(" ", "");} (That is the override method for search. See here for more details: https://www.ag-grid.com/angular-data-grid/filter-quick/)

It seems to be working for me.

Related