Templates
Each expression row in the Filter component contains a field selector, an operator selector, and a value editor. Use templates to replace any of these controls with custom components.
Fields Template
Use the kendoFilterFieldsTemplate directive to replace the built-in field selector DropDownList with any control or behavior that fits your scenario.
Common use cases include keeping the default DropDownList style while adding search filtering for long field lists, grouping fields by category, implementing templates for the list items, or replacing it entirely with a searchable ComboBox.
The following demo shows a ComboBox with incremental search in place of the default field selector. Type in the field selector to filter the available fields by name:
To configure the fields template, follow these steps:
-
Place an
<ng-template>with thekendoFilterFieldsTemplatedirective inside<kendo-filter>and bind to the two context variables the directive exposes:html<kendo-filter [value]="value" (valueChange)="onValueChange($event)"> <ng-template kendoFilterFieldsTemplate let-currentItem let-filters="filters"> <kendo-combobox [data]="filters" textField="title" valueField="field" [valuePrimitive]="true" [value]="currentItem.field" (valueChange)="onFieldChange($event, currentItem)" > </kendo-combobox> </ng-template> </kendo-filter>The template context exposes two variables:
let-currentItem—theFilterDescriptorfor the current row. SetcurrentItem.fieldto change the active field. The Filter component detects the mutation and automatically resets the row value, updates the operator list, and switches the editor type.let-filters="filters"—the full list of availableFilterExpressionitems. Use this array to populate the custom component's data source.
Operator Template
Use the kendoFilterOperatorTemplate directive to customize or replace the default operator selector DropDownList per filter field. The template receives the current FilterDescriptor as context. Read the operator of the FilterDescriptor to reflect the current selection and update it it when the user picks a new value.
This template is particularly useful when you need operators that the built-in set does not include, such as a Between option for numeric fields. Fields without the directive continue to render the built-in operator selector.
You can configure the operator template declaratively for a filter field, or assign it programmatically to a specific filter expression:
Apply the kendoFilterOperatorTemplate directive to an <ng-template> inside a <kendo-filter-field> element to declaratively implement a custom operator selector to that field.
To configure the operator template with the directive, follow these steps:
-
Add the template inside a
<kendo-filter-field>element and bind to the context variable:html<kendo-filter-field field="budget" title="Budget" editor="number"> <ng-template kendoFilterOperatorTemplate let-filter> <kendo-combobox [data]="budgetOperators" textField="text" valueField="value" [valuePrimitive]="true" [value]="filter.operator" (valueChange)="onOperatorChange($event, filter)" > </kendo-combobox> </ng-template> </kendo-filter-field>The implicit context variable
let-filterholds the currentFilterDescriptorwithfield,operator, andvalueproperties. When the user selects a null-type operator such asisnullorisnotnull, the value editor hides automatically. -
Handle operator changes by using the component's change event to update the operator when the user makes a selection. In this case, use the ComboBox
valueChangeevent:typescriptpublic budgetOperators = [ { text: 'Greater than', value: 'gt' }, { text: 'Less than', value: 'lt' }, { text: 'Between', value: 'between' } ]; public onOperatorChange(operator: string, filter: FilterDescriptor): void { filter.operator = operator; }
To assign an operator template from the component class, define an <ng-template> with a reference variable, retrieve it with @ViewChild, and set it on the operatorTemplate property of the target FilterExpression.
To apply the operator template programmatically, follow these steps:
-
Define the template outside
<kendo-filter>and add a reference variable:html<ng-template #operatorTemplate let-filter> <kendo-combobox [data]="numericOperators" textField="text" valueField="value" [valuePrimitive]="true" [value]="filter.operator" (valueChange)="onOperatorChange($event, filter)" > </kendo-combobox> </ng-template> -
Handle operator changes by using the component's change event to update the operator when the user makes a selection. In this case, use the ComboBox
valueChangeevent:typescriptpublic onOperatorChange(operator: string, filter: FilterDescriptor): void { filter.operator = operator; } -
Get a reference to the template in the component class and assign it to the target filter expression in
ngOnInit:typescript@ViewChild('operatorTemplate', { static: true }) public operatorTemplate: TemplateRef<FilterDescriptor>; public ngOnInit(): void { this.filters[0].operatorTemplate = this.operatorTemplate; }
Value Editor Template
Use the kendoFilterValueEditorTemplate directive to replace the value input for a specific filter field. Configure it declaratively inside a <kendo-filter-field>, or assign it from the component class.
You can apply the value editor template declaratively for a filter field, or assign it programmatically to a specific filter expression:
The following demo shows a custom DropDownList editor applied to every filter field with the directive:
To configure the value editor template with the directive, follow these steps:
-
Add the template inside a
<kendo-filter-field>element and bind to the context variable:html<kendo-filter-field field="country" title="Country" [operators]="operators"> <ng-template kendoFilterValueEditorTemplate let-currentItem> <kendo-dropdownlist [data]="regions" [value]="currentItem.value" (valueChange)="onEditorValueChange($event, currentItem)" > </kendo-dropdownlist> </ng-template> </kendo-filter-field>The implicit context variable
let-currentItemholds the current filter descriptor withfield,operator, andvalueproperties. -
Handle value changes by using the component's change event to update the filter value when the user makes a selection. In this case, use the DropDownList
valueChangeevent:typescriptpublic regions: string[] = ['Europe', 'Canada']; public onEditorValueChange(value: string, currentItem: FilterDescriptor): void { currentItem.value = value; }
To assign a value editor template from the component class, define an <ng-template> with a reference variable, retrieve it with @ViewChild, and set it on the editorTemplate property of the target FilterExpression.
To apply the value editor template programmatically, follow these steps:
-
Define the template with a reference variable and bind to the context variable:
html<ng-template #editorTemplate let-currentItem> <kendo-dropdownlist [data]="regions" [value]="currentItem.value" (valueChange)="onEditorValueChange($event, currentItem)" > </kendo-dropdownlist> </ng-template>The context variable
let-currentItemholds the current filter descriptor withfield,operator, andvalueproperties. -
Handle value changes by using the component's change event to update the filter value when the user makes a selection. In this case, use the DropDownList
valueChangeevent:typescriptpublic regions: string[] = ['Europe', 'Canada']; public onEditorValueChange(value: string, currentItem: FilterDescriptor): void { currentItem.value = value; } -
Get a reference to the template in the component class and assign it to the target filter expression in
ngOnInit:typescript@ViewChild('editorTemplate', { static: true }) public editorTemplate: TemplateRef<any>; public ngOnInit(): void { this.filters[0].editorTemplate = this.editorTemplate; }
The following demo shows a custom DropDownList editor applied to a filter expression from the component class: