Custom Column Filters
Summary
- Column Filters can use bespoke Custom Predicates in addition to the System Predicates that AdapTable provides
Most Column Filters use System Predicates which are shipped with AdapTable.
However Column Filters can also leverage bespoke, user-defined Custom Predicates.
Find Out More
- See Custom Predicate Definitions to learn how Developers can provide design-time Custom Predicates
- Once defined, these will be displayed in in the Filter Components and available to be used in Filters
- This example shows a Layout with 3 Column Filters each using a Custom Predicate:
Github Starsuses thePopularPredicate - which only shows values with more than 10,000 starsLanguageuses theScriptingPredicate - which limits values to 'JavaScript' or 'TypeScript' (we also created a Conditional Style using this Predicate)Createdhas theLast Ten YearsPredicate applied - which filters to dates in previous 10 - and has a Scope of allDatecolumns
- Clear the
ScriptingFilter in theLanguagecolumn and note how the cells with 'HTML' are not formatted (since they do not pass the Predicate which is still being used for Formatting)
Users can create as many Custom (and System) Column Filters as required and AdapTable will automatically update AG Grid so that only rows which match all Filters will be displayed.
Predicate Inputs
Custom Filters, like all Predicates, are able to accept inputs - so they can be given a dynamic argument.
- This demo creates a Custom Filters that receives an input
Long Stringhas acolumnScopeof String columns, and receives a number input which verifies if the string is big or not
- Create a Column Filter on the
LanguageColumn using theLong StringCustom Predicate and an input of 5: note that the 2 rows with HTML will be filtered out
Custom Time Filters
Custom Filters are useful when you want to filter a Date Colum using only Time.
AdapTable provides a large number of System Filters but they all operate on a Date, not the Time portion only.
Hint
This is particularly useful if you have a "Day Activity Grid" which just displays entries for a single day
- This demo creates 2 Custom Filters that use Time (both have
columnScopeof thePushedcolumn which we have changed to just show Times for today):Overnightreturns true if the time in the Column is between midnight and the start of the day (9am)Recentreceives a numeric input and returns true if the value is within the inputted number of hours
- Note: we also removed some Date System Predicates to make it easier to see the 2 Custom Predicates
- Run Column Filter on
PushedColumn usingMidnightCustom Predicate and note only values before 9am appear - Run Column Filter on
PushedColumn usingRecentCustom Predicate and an input of 5 and note: only rows with a value in last 5 hours are displayed
Referencing Other Columns
The handler property used when evaluating Custom Predicates is given the current row node in its context.
This allows you to create Custom Filters that reference other Columns in the Row as part of the evaluation.
- This demo creates 2 Custom Filters that reference other Columns in the Row for its evaluation:
Big Starsreturns true forGithub StarsColumn if it is greater than 10,000 andGithub Watchersis over 200Successreturns true forClosed IssuesColumn if it is greater than theClosed PRsColumn
Overriding System Filters
In addition to providing new Custom Filters, developers can provide Custom Filters which override the System Predicates shipped by AdapTable.
Hint
Make sure that the Custom Predicate has the same id as the System Predicate it replaces
This replaces the implementation for the System Filter provided by AdapTable with the custom behaviour.
Note
- The Custom Predicate is placed in the same position in the Filter List as the System Predicate it replaces
- The icon which is displayed in the Filter Predicate dropdown is that of the overridden System Predicate
Find Out More
See Overriding System Predicates for more information and a full, explanatory, demo