# Configuring a DateTimePicker Filter in Grid Column Menu

## Environment

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

## Description

By default, the DatePicker is the built-in filtering component for date columns in the Grid. How can I customize the default column menu filter of the Grid and implement a DateTimePicker filter for date columns?

## Solution

To customize the column menu filter of the Grid with a DateTimePicker for date columns, create [a custom filter component](https://www.telerik.com/kendo-angular-ui/components/grid/filtering/filter-menu#custom-filter-menu-components) and use it within the [`FilterMenuTemplateDirective`](https://www.telerik.com/kendo-angular-ui/components/grid/api/filtermenutemplatedirective). The next steps go into more detail about how to achieve the suggested approach:

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

   ```html
   <kendo-grid-column field="FirstOrderedOn" title="First Ordered On">
       <ng-template
           kendoGridFilterMenuTemplate
           let-column="column"
           let-filter="filter"
           let-filterService="filterService">
         ...
       </ng-template>
   </kendo-grid-column>
   ```

2. In a separate file, create a custom component containing a DateTimePicker that will take as inputs the `filter` and `FilterService` fields, passed by the context of the `FilterMenuTemplateDirective`.

   ```html
   <kendo-grid-column field="FirstOrderedOn" title="First Ordered On">
       <ng-template
           kendoGridFilterMenuTemplate
           let-column="column"
           let-filter="filter"
           let-filterService="filterService">
           <my-date-time-filter
               [field]="column.field"
               [filter]="filter"
               [filterService]="filterService">
           </my-date-time-filter>
       </ng-template>
   </kendo-grid-column>
   ```

3. Set the value of the DateTimePicker to the current column filter upon the initialization of the component.

   ```ts
   public ngOnInit(): void {
       const currentColumnFilter =
           this.filter.filters.find(
               (filter: FilterDescriptor) => filter.field === this.field
           );
       if (currentColumnFilter) {
           this.value = (currentColumnFilter as FilterDescriptor).value;
       }
   }
   ```

4. Handle the built-in [`valueChange`](https://www.telerik.com/kendo-angular-ui/components/dateinputs/api/datetimepickercomponent#valuechange) event of the DateTimePicker and use the `filter()` method of the `filterService` to set the current column filter.

   ```ts
   public onValueChange(value: Date): void {
       const filters = [{
           field: this.field,
           operator: 'eq',
           value: value,
       }];

       this.filterService.filter({
           logic: 'and',
           filters: filters,
       });
   }
   ```

5. Prevent the column menu from closing upon clicking in the DateTimePicker's calendar popup by following the manner demonstrated in the [Filter Menu with Popup](https://www.telerik.com/kendo-angular-ui/components/grid/filtering/filter-menu#filter-menu-with-popup) article.

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

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

## See Also

* [Custom Filter Menu Components](https://www.telerik.com/kendo-angular-ui/components/grid/filtering/filter-menu#custom-filter-menu-components)
* [Implementing a DateTimePicker Filter Row in Grid](https://www.telerik.com/kendo-angular-ui/components/knowledge-base/datetimepicker-grid-filter-row)
* [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)
