telerik / kendo-examples-asp-net-mvc

Kendo UI Examples for ASP.NET MVC
164 stars 250 forks source link

Unable to filter date fields #7

Open ithardeep opened 8 years ago

ithardeep commented 8 years ago

Hello,

I am not able to use filters on date fields, I did some search and found kendo sends date to server in this format "2016-03-21T18:30:00.000Z".

Since I am using property of Datetime, so I am getting error, please take a look. http://i.imgur.com/mCU7EJ0.png

Can you please take a look and let me know any workaround. Thanks

mcarrera commented 7 years ago

I placed this hack in the Filter method of QueryableExtensions.cs It assumes your date field contains the string date, and no other fields contains the same string

 if (predicate.ToLower().Contains("date"))
                {
                        for (var i =0; i < values.Length; i++)                    {
                        values[i] = DateTime.Parse(values[i].ToString());
                    }
                }

I also needed to strip time from date properties in my queryable object. Otherwise the = filter would not work (in my case I only consider date, not time.)