Text Filter
Text filters allow you to filter text data. The pages Provided Filters and Provided Simple Filters explains the parts of the text filter that are similar to the other provided filters. This page builds on that and explains some details that are specific to the text filter.
Text Custom Comparator
By default the text filter does strict case insensitive text filtering: ie If you provide as data for a text column the following values ['1,234.5USD', '345GBP']:
- contains '1,2' Will show 1 value: ['1,234.5USD']
- contains '12' Will show 0 values
- contains '$' Will show 0 values
- contains 'gbp' Will show 1 value ['345GBP']
You can change the default behaviour by providing your own textCustomComparator. Using your own textCustomComparator
you can provide your own logic to decide when to include a row in the filtered results.
The textCustomComparator is a function with the following signature:
filter:stringThe applicable filter type being tested. One of: {equals, notEqual, contains, notContains, startsWith, endsWith}gridValue:anyThe value about to be filtered, if this column has a value getter, this value will be coming off the value getter, otherwise it is the raw value injected into the gridfilterText:stringThe value to filter by.returns:booleanTrue if the value passes the filter, otherwise false.
The following is an example of a textCustomComparator that mimics the current implementation of ag-Grid. This can be used as a template to create your own.
Text Formatter
The grid compares the text filter with the values in a case insensite way, thus 'o' will match 'Olivia' and 'Salmon', however it will not match against 'Björk'. If you want to match in any other way (eg you want to makes against accents), or you want to have case sensitive matches, then you should provide your own textFormatter.
The textFormatter is a function with the following signature
- gridValue:string The value coming from the grid. This can be the valueGetter if there is any for the column, or the value as originally provided in the rowData
- returns:string The string to be used for the purpose of filtering.
If no textFormatter is provided the grid will convert the text to lower case. Is important to note that when
comparing to the text entered in the filter box, the text in the filter box is converted always to lower case.
The following is an example to remove accents and convert to lower case.
Example Text Filter
- The athlete column has only two filter options:
filterOptions=['contains','notContains'] - The athlete column has a text formatter so if you search for 'o' it will find ø You can try this by searching the string 'Bjo'
-
The athlete column has a debounce of 0ms
debounceMs:0. This is used by both the parent and floating filter components. - The athlete column filter is case sensitive, note that it has the following flag:
caseSensitive:true - The athlete column filter has the AND/OR additional filter suppressed, note that it has the following flag:
suppressAndOrCondition:true - The country column has only one filter option:
filterOptions=['contains'] - The country column has a
textCustomComparatorso that there are aliases that can be entered in the filter ie: if you filter using the text 'usa' it will match United States or 'holland' will match 'Netherlands' -
The country column filter has a debounce of 2000ms
debounceMs:2000 - The year column has one filter option
filterOptions=['inRange']. - The sports column has a different default option
defaultOption='startsWith'