New to Kendo UI for AngularStart a free 30-day trial

Implementing a DateTimePicker Filter Row in Grid

Environment

ProductProgress® Kendo UI for Angular Grid

Description

How to implement a DateTimePicker as a custom Grid filter row component?

Solution

By default, the Grid uses the DatePicker as the built-in component when filtering a date column. To use DateTimePicker instead, customize the default filter with the FilterCellTemplateDirective.

  1. Use the FilterCellTemplateDirective in the column whose filter needs to be customized.

    html
    <kendo-grid-column field="FirstOrderedOn">
        <ng-template kendoGridFilterCellTemplate let-filter>
            ...
        </ng-template>
    </kendo-grid-column>
  2. In a separate file create the DateTimePicker component that is going to act as a filter in the Grid.

    html
    <kendo-datetimepicker (valueChange)="onChange($event)" [format]="'dd/MM/yyyy'">
    </kendo-datetimepicker>
  3. Handle the DateTimePicker's built-in valueChange event and use the applyFilter and updateFilter methods of the BaseFilterCellComponent to filter the column.

    ts
    export class DateTimeFilterComponent extends BaseFilterCellComponent {
        ...
        constructor(filterService: FilterService) {
            super(filterService);
        }
    
        public onChange(value: any): void {
            this.applyFilter(
                this.updateFilter({
                    field: this.valueField,
                    operator: 'eq',
                    value: value
                })
            );
        }
    }
  4. To clear the filter, handle the click event of a button and use the removeFilter method of the BaseFilterCellComponent.

    ts
    public clearFilter() {
        this.applyFilter(this.removeFilter('FirstOrderedOn'));
        ...
    }    
  5. Optionally, you can toggle the visibility of the button based on the applied filter with the *ngIf Angular directive.

    html
    <button kendoButton *ngIf='clearButton' ...></button>

The following example shows the full implementation of the described approach.

Change Theme
Theme
Loading ...

See Also

In this article
EnvironmentDescriptionSolutionSee Also
Not finding the help you need?
Contact Support