FilterBuilder
FilterBuilder builds a filter as a tree of conditions: groups joined by AND or OR, optionally negated, holding rules and sub-groups. Each field type has its operators and its value editor, the value is a serializable expression, and the exported utilities filter an array in memory, write a readable summary or convert the filter for a Table.
Import #
import { FilterBuilder, filterBuilderToPredicate, filterBuilderToText } from '@exhaustive-ui/core/filterbuilder';Basic #
FilterBuilder is bound with ngModel and needs the fields the rules can filter on, each with a name, a label and a type. A rule is a field, an operator and a value; the operators and the value editor follow the type of the field. The value is a plain, serializable tree: a group with a logic and its filters, ready to store or to send to an API.
Category is Accessories Price is less than
{
"logic": "and",
"filters": [
{
"field": "category",
"operator": "equals",
"value": "Accessories"
},
{
"field": "price",
"operator": "lt",
"value": 100
}
]
}Field Types #
Each type has its operators and its value editor, built from the form components of the library:
- text: contains, does not contain, is, is not, starts with, ends with, with an InputText.
- number: is, is not, is less than, is at most, is greater than, is at least and between, with one or two InputNumbers.
- date: is, is not, is before, is after and between, with one or two DatePickers, compared by calendar day.
- boolean: is, with a ToggleSwitch.
- select: is and is not with a Select, is any of and is none of with a MultiSelect.
- multiselect: for a field whose data is an array, such as tags: has any of, has none of and is exactly, with a MultiSelect.
Every type also has is empty and is not empty. The operators of a field replace the defaults of its type for this field, the operators input replaces them for a whole type, and defaultOperator is selected when the field is picked. The options are label and value pairs, or plain values.
Name starts with Price is between Release date is after In stock is Status is any of In stock, Low stockTags has any of eco
Nested Groups #
A group joins its rules and sub-groups with AND or OR, and its NOT toggle negates it. Add group adds a sub-group with an empty rule, down to maxDepth levels, the root group being the first one; maxDepth 1 allows no sub-group, and showNot removes the NOT toggles. In the value, a sub-group is an item of filters with its own logic, not and filters.
Total is at least - Logic of group 1.1
Country is France - Logic of group 1.1.1
Paid is
Custom Value Editor #
An ng-template with the pFilterBuilderEditor directive replaces the value editor of the fields it names, here a Rating for the rating field; without a name it replaces the editor of every field. The context gives the value as the implicit variable, the field, the operator, a setValue function, the ariaLabel to give to the editor, and the invalid and disabled states.
Rating is at least
Filter a Table #
filterBuilderToPredicate(expression, fields) turns the value into a function for Array.filter, to filter data in memory, here the rows of a Table. The incomplete rules and the empty groups are ignored, so an empty filter keeps every row; texts are compared without case and accents, dates by calendar day, and the between bounds are included. A dotted field name such as supplier.country reads a nested property, and the resolve option reads the fields in any other way.
Category is any of Accessories, Fitness- Logic of group 1.1
Price is less than Tags has any of new
5 of 12 products
| Name | Category | Price | Stock | Released | Tags |
|---|---|---|---|---|---|
| Blue Band | Fitness | 79 | 2 | 2026-05-20 | |
| Bracelet | Accessories | 15 | 73 | 2024-12-01 | |
| Chakra Bracelet | Accessories | 32 | 5 | 2026-06-08 | |
| Yoga Mat | Fitness | 20 | 15 | 2026-02-11 | |
| Yoga Set | Fitness | 20 | 25 | 2024-09-03 |
Text Summary #
filterBuilderToText(expression, fields) writes a readable summary of the filter, for a collapsed filter bar, a saved search or a confirmation. The fields give the labels of the fields and of the options; the locale option formats the dates and numbers, and the labels option translates the words. The incomplete rules are left out, and an empty filter gives an empty string.
Priority is any of Medium, High- Logic of group 1.1
Assigned is Created is before
- Logic of group 1.2
Title contains
Priority is any of Medium, High AND (Assigned is No OR Created is before Nov 1, 2026) AND NOT (Title contains "test")
Table Filters #
filterBuilderToTableFilters(expression, fields) converts the filter to the filters of a Table, { [field]: FilterMetadata[] }, for a Table that filters on the server with lazy loading or keeps its own column filters. A Table joins the fields with AND and the rules of one field with a single AND or OR, so the conversion succeeds for an AND group of rules, or of sub-groups whose rules all filter the same field, and for an OR group on a single field. It returns null for anything else: a NOT, an OR across fields, the is empty, is not empty and is none of operators, multiselect fields and dates compared with between. In those cases, filter with filterBuilderToPredicate or send the expression itself to the server.
Name starts with - Logic of group 1.1
Balance is less than Balance is greater than
Status is any of qualified, new
{
"name": [
{
"value": "J",
"matchMode": "startsWith",
"operator": "and"
}
],
"balance": [
{
"value": 1000,
"matchMode": "lt",
"operator": "or"
},
{
"value": 50000,
"matchMode": "gt",
"operator": "or"
}
],
"status": [
{
"value": [
"qualified",
"new"
],
"matchMode": "in",
"operator": "and"
}
]
}Validation #
A rule is incomplete while its field, its operator or the value its operator needs is missing. Once the focus leaves an incomplete rule, the rule and its missing controls are shown as invalid, with a message linked to the rule; markAllAsTouched() or the touched input shows every incomplete rule at once. The valid() and incomplete() signals and the onChange event tell the state, and the form control gets a filterBuilder error.
onlyValid emits the filter without its incomplete rules and empty groups, and only when this complete part changes: picking a field or typing in a new rule does not emit it. Use it to run a search only when the filter really changes; filterBuilderPrune gives the same result from any value.
Searches run: 0. Rules applied: 0.
Forms #
Template Driven #
The component adds a filterBuilder error, with the number of incomplete rules, while a rule is incomplete. Bind touched to show every incomplete rule once the form is submitted, and name the filter with ariaLabelledBy.
Reactive Forms #
FilterBuilder can also be used with reactive forms, through the formControlName property. The filterBuilder error is added by the component itself, and the value written with setValue or reset rebuilds the tree.
Signal Forms #
FilterBuilder can also be used with Angular Signal Forms. The [formField] directive binds the component to a field of the expression type, and sets its touched state, so the incomplete rules are shown once the field is touched or the form submitted. Check the rules in the schema with filterBuilderIncomplete and filterBuilderCount in validate rules.
Accessibility #
Screen Reader
Every group is an element with the group role named by its number, such as Group 1 or Group 1.2 for the second sub-group of the root group; name the root group with ariaLabel or ariaLabelledBy. Its items are a list, and every rule is also a group, named Rule 2 in group 1. Each control of a rule says which rule it belongs to: Field for rule 2 in group 1, Operator for rule 2 in group 1, Value for rule 2 in group 1, and Start value and End value for the two editors of between. The icon buttons are named in the same way, Duplicate rule 2 in group 1 and Remove group 1.1, and the buttons with a text, Add rule and Add group, keep their text at the start of their name.
The logic of a group is a SelectButton named Logic of group 1, whose buttons are pressed or not, and NOT is a toggle button with aria-pressed. The AND and OR words shown between the items repeat the logic and are hidden from screen readers.
Adding, duplicating and removing a rule or a group is announced by a polite live region, such as Rule 3 added to group 1. The focus then moves to the field of the new rule, or after a removal to the next item, the previous one, or the Add rule button of the group when it is empty, so it is never lost. An incomplete rule that the focus left gets aria-invalid on its missing controls and a message linked with aria-describedby. Every text can be replaced, or translated, with the labels input, where {0} and {1} are the numbers of the rule and of the group.
<span id="filter-label">Products to export</span>
<p-filter-builder [(ngModel)]="filter" [fields]="fields" ariaLabelledBy="filter-label" />
<p-filter-builder [(ngModel)]="filter" [fields]="fields" ariaLabel="Filtre" [labels]="{ groupLabel: 'Groupe {0}', fieldLabel: 'Champ de la règle {0} du groupe {1}', addRule: 'Ajouter une règle', addRuleLabel: 'Ajouter une règle au groupe {0}' }" />Keyboard Support
FilterBuilder is made of standard controls in reading order, with no keyboard trap: each group gives its NOT toggle, its logic and its buttons, then its rules and sub-groups.
| Key | Function |
|---|---|
| tab / shift + tab | Moves the focus to the next or the previous control of the tree. |
| enter / space | On a button, adds a rule or a group, duplicates or removes a rule, removes a group, toggles NOT, or selects the AND or OR logic. |
| enter / space / down arrow | On the field, operator or value Select, opens the list of options; up arrow and down arrow move in it, enter selects and escape closes it. |
| any character | Types in the text and number values; in the date values, the DatePicker also opens its calendar with down arrow. |