Filtering on DateTime values

4 posts, 0 answers
  1. Marc
    Marc avatar
    2 posts
    Member since:
    Aug 2014

    Posted 21 Aug 2014 Link to this post

    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

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Aug 2014 Link to this post

    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.
     
  3. Marc
    Marc avatar
    2 posts
    Member since:
    Aug 2014

    Posted 22 Aug 2014 in reply to Dimitrina Link to this post

     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
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 26 Aug 2014 Link to this post

    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.
     
Back to Top