# Implementing a DateTimePicker Filter Row in Grid

## Environment

<table>
    <tbody>
        <tr>
            <td>Product</td>
            <td>Progress® Kendo UI for Angular Grid</td>
        </tr>
    </tbody>
</table>

## 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`](https://www.telerik.com/kendo-angular-ui/components/grid/api/filtercelltemplatedirective).

1. Use the [`FilterCellTemplateDirective`](https://www.telerik.com/kendo-angular-ui/components/grid/api/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`](https://www.telerik.com/kendo-angular-ui/components/dateinputs/api/datetimepickercomponent#valuechange) event and use the `applyFilter` and `updateFilter` methods of the [`BaseFilterCellComponent`](https://www.telerik.com/kendo-angular-ui/components/grid/api/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](https://angular.dev/api/common/NgIf#) Angular directive.

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

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

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/knowledge-base/datetimepicker-grid-filter-row/source.txt)

## See Also

* [Custom Filter Row Components](https://www.telerik.com/kendo-angular-ui/components/grid/filtering/filter-row#custom-filter-row-components)
* [Configuring a DateTimePicker Filter in Grid Column Menu](https://www.telerik.com/kendo-angular-ui/components/knowledge-base/datetimepicker-columnmenu-filter)
* [Kendo UI for Angular Grid Filtering Basics](https://www.telerik.com/kendo-angular-ui/components/grid/filtering/basics)
* [Kendo UI for Angular DateTimePicker Overview](https://www.telerik.com/kendo-angular-ui/components/dateinputs/datetimepicker)
