# Using Search Box to Filter the Grid Data by Date

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Grid</td>
 </tr>
  <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>2022.1.119</td>
 </tr>
</table>

## Description

How can I filter the Grid's data by a `DateTime` field with the Search tool? It recognizes strings formatted like dates as integers, for example, 07/08/1996 is parsed as 07.

## Solution

When the Grid is bound to a numeric field and the search input includes numbers the input is parsed as a number by default.

To change this behavior, configure the `Schema.Model.Parse` property of the Numeric field to use a JavaScript handler function. To prevent the parsing of the date as a number, look for special date symbols in the handler and return null if there are any.

### Client Operations

For a runnable sample of the Client-side operations approach refer to this [Telerik REPL](https://netcorerepl.telerik.com/mmaowUPI25QV9sSD08).

```Razor View.cshtml
    .DataSource( dataSource => dataSource
        .Custom()
        ...
        .Schema(schema =>
        {
            schema.Model(model =>
            {
                model.Id(x => x.OrderID);
                model.Field(p => p.Freight).Parse("parseFreight");
                model.Field(p=>p.OrderDate);
                model.Field(p => p.ShipName);
            });
            schema.Data("Data");
            schema.Total("Total");
        })
    )

    <script>
        function parseFreight(val){
            var s = val.toString();
            if (s.indexOf("/") !== -1) {
                return null;
            }
            return kendo.parseFloat(val);
        }
    </script>
```

### Server Operations

For a runnable sample of the Server-side operations approach refer to this [Telerik REPL](https://netcorerepl.telerik.com/cmOIQqFy26LMASWU44).

```Razor View.cshtml
    .DataSource( dataSource => dataSource
        .Custom()
        ...
        .ServerFiltering(true)
        .ServerPaging(true)
        .Schema(schema =>
        {
            schema.Model(model =>
            {
                model.Id(x => x.OrderID);
                model.Field(p => p.Freight).Parse("parseFreight");
                model.Field<DateTime?>(p=>p.OrderDate);
                model.Field(p => p.ShipName);
            });
            schema.Data("Data");
            schema.Total("Total");
        })
    )

    <script>
        function parseFreight(val){
            var s = val.toString();
            if (s.indexOf("/") !== -1) {
                return null;
            }
            return kendo.parseFloat(val);
        }
    </script>
```

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)

* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)
* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
