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

DateTime column sort and filter don't work as expected together

3 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Barnabas
Top achievements
Rank 1
Barnabas asked on 04 Nov 2010, 05:55 PM
I have a column that is a System.DateTime value. I am displaying the entire date and time. All of the examples on the demo site only display the Date.

If the DateTime column has a sort applied to it, life is good. However if a filter is applied to it, things get complicated. The datepicker only allows the user to select a date. After the user picks a date the filter uses a System.DateTime that has the default value of midnight populated for the time value. This creates some unexpected behavior.

The grid can contain 3 items with a DateTime value of 10/05/2010 and various times throughout the day.
The user can select a filter of "is equal to" and then use the datepicker to select a date of 10/05/2010.
The user would expect the 3 items with a date equal to the date they selected to be returned.
In fact no dates are returned. The grid creates a filter that looks for records with a System.DateTime equal to 10/05/2010 12:00:00 AM. No records match that filter so no records are returned.

This seems like a bug to me. I am open to suggestions on how to fix this issue. Thanks so much.

Barnabas

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 05 Nov 2010, 08:25 AM

Hi,

If no time is entered by the end user then I think it is correct that some default time is picked. And provided the filtering operator is 'equals' the dates do not match. We have specially made it that way because there are users who will enter full time and date and expect only the matching records to appear when the operator is 
'equals'. If this behavior is not what you want you may consider using custom binding. Then you can create the right filtering expression and use only the date part of the datetime.

If you have set the format of the column (e.g. .Format("{0:MM/dd/yyyy HH:mm}") ) then the datepicker in the filtering UI would accept the same format (including time).

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Barnabas
Top achievements
Rank 1
answered on 11 Nov 2010, 06:29 PM
Atanas,

I have not been able to find a way to enter the time into the datepicker field for the DateTime filter. If I type in the time it is always removed whenever focus is moved away from the field. Thus, the only time that I can ever filter with is midnight. I believe you are mistaken about the ability to enter a time into a datepicker field. Thus your well intentioned fix does not address the issue.

Possible fixes:

1) When filtering a column bound to DateTime, sort by time and filter by date only. By allowing the user to only choose a date with the datepicker, this is the behavior you are leading them to expect.

2) When filtering a column bound to DateTime, provide a DateTime picker. I know this control is brand new, but this seems like a great solution.

3) Explicitly state that you do not support filtering a column bound to a value that has both Date and Time.

There are probably more solutions. These are just the ones that appear to me right now.

Thanks for your assistance,
Barnabas

0
Atanas Korchev
Telerik team
answered on 12 Nov 2010, 08:59 AM
Hi Barnabas,

 If you set the format of the column to one which includes time the date picker will accept time as well. I am sending a sample project showing that.

You are right about the datetimepicker in the filtering menu. The only drawback of this approach is the extra JavaScript file which end users will need to include. Still I think we can make it work! Thanks for the idea! The way we think of doing it is to rely on the DataType metadata attribute. By default we will continue rendering a datepicker but if the property is decorated with [DataType(DataType.DateTime)] we will output a datetimepicker. That way we would not break existing customers and still allow to use the datetimepicker.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Barnabas
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Barnabas
Top achievements
Rank 1
Share this question
or