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

Filtering on DateTime values

3 Answers 281 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 21 Aug 2014, 03:09 PM
I have a column of Datetimes that have unique times for same dates. I want to not show the duplicates when filtering.
Based on this page http://www.telerik.com/help/wpf/gridview-filtering-faq-datetime-filtering.html all I need to do is write the following
 DataMemberBinding="{Binding BirthDate.Date}"

However all this does is remove the filter completely..

Any suggestions ?

thanks

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Aug 2014, 11:49 AM
Hi,

What do you mean by "unique times for same days"?
As you have set the DataMemberBinding="{Binding BirthDate.Date}", only the Date values will be displayed (without time) in both the cells' content and in the FilteringControl distinct filters' list. They may look as if they are duplicated in the cells as all the data (each item in the collection) is going to be displayed. In the FilteringControl, only the distinct values will be displayed though. They should be only unique dates, without considering the times.

For example, if you have the today's date with different times, in the FilteringControl you should see the today's date only once.

Would you please clarify what do you mean that the filter is removed completely? Is it not possible at all any more, or do you not see any values when opening the FilteringControl?

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Marc
Top achievements
Rank 1
answered on 22 Aug 2014, 04:01 PM
 Hi Didie
1.) 'unique times for same days' is values with the same days but different times.  
ie 
2002-10-26 02:47:09.000
2002-10-26 02:38:23.000
2002-10-26 02:30:37.000
 
2.) See attached for an image of the removed filter. 

Actually I think I've figured out the issue
Here is the  grids xaml
 <telerik:RadGridView x:Name="grdTemp"
                                     AutoGenerateColumns="False"
                                     ItemsSource="{Binding TaskDetails}"
                                     SelectedItem="{Binding SelectedTaskDetail, Mode=TwoWay}">
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn Header="Add Date"
                                                    DataMemberBinding="{Binding AddDate.Date}" />
                     </telerik:RadGridView.Columns>
                </telerik:RadGridView>

The problem is that the AddDate prop is a nullable DateTime (ie DateTime?). If I remove the nullable the functionality works as expected.
So I presume that I have to use a non nullable Datetime?

Thanks
Marc
0
Dimitrina
Telerik team
answered on 26 Aug 2014, 07:47 AM
Hi,

The reason why the columns bound to NullableDate.Date is that the DateTime? objects do not have a Date property. 
When filtering will be performed, then the LINQ query to be executed looks like:

var filteringResult = (clubsGrid.SelectedItems as ObservableCollection<Club>).Where(date => date.BirthDate.Date == DateTime.Now.Date);


This is actually an invalid query as the BirthDate property does not have a Date property to access. Therefore the filtering query cannot be executed. That is why the filtering option is disabled for that particular column.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Marc
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Marc
Top achievements
Rank 1
Share this question
or