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

Ignore Time when Filtering on RadDateTimeColumn

2 Answers 379 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Casey
Top achievements
Rank 1
Casey asked on 04 Nov 2009, 02:23 PM
Hello,

I'm trying to achieve the following functionality. I have a RadGrid that contains a GridDateTimeColumn, with filtering enabled. This field is populated from a SqlDataSource that selects a DATE column from an Oracle table. The column in the RadGrid shows the date along with the time, that is fine as the RadGrid is being used like a log. What I would like is that when the user selects a date to filter on, ONLY the date part of the filter is looked at, and all entries with that date are displayed in the RadGrid. What is happening, and I believe this is the expected behavior, is that the RadGrid is actually filtering for 11/3/2009 12:00 AM, instead of just 11/3/2009. Is it possible to achieve this desired filtering functionality?

I thought maybe something could be done during the RadGrid1_ItemCommand event, but I couldn't figure out how to say: Use 11/3/2009 for filter and compare to only the date part of the value in the column. I think it is possible to achieve the first part of what I said (modifying the e.CommandArgument text), but I don't know how to tell the RadGrid to only look at the first part of the GridDataItem text.

Thanks,
Casey 

2 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 09 Nov 2009, 09:25 AM
Hi Casey,

Indeed, the behavior which you mentioned is observed. However, it is expected. When the filtering is performed, it tries to match the complete value, against whatever value is present in the database. Hence, if there is a "11/3/2009 12:00 AM" value in the database, the filter value should match this value. There are two options in this aspect.
First, you can have a sperate field in the underlying datasource, which contains the data in the "short" format. You can bind the control to this field, and the filtering will be handled as per your logic.
Alternatively, you can attach to the ItemCommand event handler of the grid, intercept the value entered by the user, and alter it in accordance with the desired format. This would allow the values to be properly compared.
I hope these suggestions get you started properly.

Kind regards,
Yavor
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
Robert Jordan
Top achievements
Rank 1
answered on 16 Jun 2011, 04:24 PM
Seems that since the Model attribute [DataType(DataType.Date)] is respected by the grid automatically to control the suppression of the time part of the date, that the filters could observe this attribute on the bound model and adjust the filter automagically to disclude the time part.

A fairly trivial workaround that doesn't require modification of the data source is to handle the truncation in the model:

        private DateTime? lastUpdatedOn { getset; }
 
        [DisplayName("Last Modified")]
        [DataType(DataType.Date)]
        public DateTime? LastUpdatedOn
        {
            get
            {
                return lastUpdatedOn.HasValue ? lastUpdatedOn.Value.Date : lastUpdatedOn;
            }
        }

The DataType will suppress the time display in the grid, but the bound data will have a value of 12:00:00 AM for all the times, regardless of the private value.
Tags
Grid
Asked by
Casey
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Robert Jordan
Top achievements
Rank 1
Share this question
or