This is a migrated thread and some comments may be shown as answers.

[Solved] FilterTemplate with Date and Time filter

3 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
saritha78
Top achievements
Rank 1
saritha78 asked on 29 Dec 2009, 12:45 AM
I am using the example from here to implement filtering of a column using DateTime field. I have the following dataformatstring for my gridbound column

<telerik:GridBoundColumn DataField="Date" HeaderText="Date" UniqueName="Date" DataFormatString="{0:MM/dd/yyyy hh:mm:ss}" > 

If I use the scriptblock from the example,the toDate for the filter does not include the time portion and it defaults to 12:00 AM and so, it behave like the filter is exclusive of the To date. How do I make it inclusive, so that the filtered data includes the date selected in the ToDate datepicker?

Thanks in advance,
Saritha

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 29 Dec 2009, 04:45 PM
Hi Saritha,

Attached is a sample where I tried to reproduce the problem but to no success. Could you take a look at it and get back with more information on how to reproduce the issue.

Thanks.

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
saritha78
Top achievements
Rank 1
answered on 29 Dec 2009, 06:48 PM
Hi Tsvetoslav,
Thanks for your reply.
Your solution works on the data as is and all the order dates have a time of 12:00:00AM by default. When I changed the Order Date in the table dbo.orders to have some real time data like

7/4/1996 8:00:00 AM
7/5/1996 9:00:00 AM
7/8/1996 10:10:00 AM
7/8/1996 11:09:00 AM
7/9/1996 1:10:00 PM

The filtering now does not work. What I mean is, when I select To Date in the filter as 7/9/1996, it no longer shows the row with the datetime of 7/9/1996 1:10:00 PM for the order date.
To reproduce the problem, update the order date in you Northwind database, dbo.Orders table to have time part of the data to be something other than 12:00:00 AM and run your website. Filter to the date that you changed in the data and it will not show up in the filtered data.
Thanks,
Saritha
0
Veli
Telerik team
answered on 04 Jan 2010, 01:33 PM
Hi Saritha,

The behavior you observe is expected. When you filter with the two date pickers, your date is formatted to the display format of your date picker, i.e. to MM/dd/yyyy. As you can see, this format does not include any time portion, therefore, on the server, your parsed date has a default time of 12:00 AM. In this case, filtering dates up to and including 7/9/1996 excludes any dates after 7/9/1996 12:00 AM.

If you need to filter your dates up to and including some time, you will need  to use custom filtering where you would manually filter your data source and rebind your grid. Fore more information on the FilterTemplate:

Filter template

Basically, you would need to use the server-side SelectedDateChanged events of the two pickers with AutoPostBack="True" and you would set your filter expression in the event handlers. Attached is the reworked version of the sample project you have been referred to by Tsvetoslav.

All the best,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
saritha78
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
saritha78
Top achievements
Rank 1
Veli
Telerik team
Share this question
or