RadGridView GridViewDataColumn DateTime Filter (RadDateTimePicker) on Time part (hh:mm:ss tt).

5 posts, 1 answers
  1. Ravin
    Ravin avatar
    16 posts
    Member since:
    Jun 2012

    Posted 18 Aug 2015 Link to this post

    Good morning,

    I have a RadGridView with GridViewDataColumns which have ShowDistinctFilters="False" and contain DateTime values from an Odata service collection.

    I want to have the RadDateTimePicker control in the filter for the GridViewDataColumn to let me filter on the "Time" portion of the DateTime object.

    Currently my mark-up for a column is:

    <telerik:GridViewDataColumn ShowDistinctFilters="False" DataMemberBinding="{Binding ADD_DATE}" Header="Date Added" />

    This gives me the result of telerik_data_filter_date_time_example.png when I try to filter.

    What I want is to also have the time portion (hours, minutes, and seconds) selectable in those filters. I can accomplish this in a RadDataFilter control if I set EditorCreated="radDataFilter_EditorCreated" and then have the following code (mainly from line 9 of the below snippet):

    01.private void radDataFilter_EditorCreated(object sender, EditorCreatedEventArgs e)
    02.{
    03.    if (e.ItemPropertyDefinition.PropertyType.Equals(typeof(DateTime)))
    04.    {
    05.        RadDateTimePicker dateTimePickerEditor = e.Editor as RadDateTimePicker;
    06.        dateTimePickerEditor.InputMode = DateTimePicker;
    07.        dateTimePickerEditor.Culture = new CultureInfo("en-US");
    08.        dateTimePickerEditor.Culture.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
    09.        dateTimePickerEditor.Culture.DateTimeFormat.ShortTimePattern = "hh:mm:ss tt";
    10.    }
    11.     
    12.    /* snipped remaining part of the method */
    13.}

    Is there any way I can create the same effect within the filters on the RadGridView for that GridViewDataColumn that contains DateTime values? I'd prefer a XAML solution for this if possible, but if necessary, I can use a code behind solution as well.

     

    Thanks!

  2. Ravin
    Ravin avatar
    16 posts
    Member since:
    Jun 2012

    Posted 18 Aug 2015 in reply to Ravin Link to this post

    I forgot to mention that telerik_data_filter_date_time_example_2.png shows the result of the RadDataFilter control ​with the custom behavior defined from handling the EditorCreated event.

    It doesn't look like there is any way to edit existing posts on this forum as a non-admin user.

    Thanks

  3. DevCraft banner
  4. Ravin
    Ravin avatar
    16 posts
    Member since:
    Jun 2012

    Posted 18 Aug 2015 Link to this post

    Sorry, correction to the above 2 posts.

    The attachment on this post telerik_data_filter_date_example.png refers to the situation described at the top of the first message where telerik_data_filter_date_time_example.png is referenced, telerik_data_filter_date_time_example.png is an older version of telerik_data_filter_date_time_example_2.png and doesn't need to be included at all.

    The attachment telerik_data_filter_date_time_example_2.png does indeed show the result of the RadDataFilter control ​with the custom behavior defined from handling the EditorCreated event as mentioned in my second post.

    If someone can please edit my original post to reflect this and add in the new attachment, then these 2 posts can be deleted.

    Thanks!

  5. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 Aug 2015 Link to this post

    Hi,

    You can refer to the Filtering documentation and more specifically:
    Filter on Date value only (it explains how to customize the filter and a similar approach can be used not for Date only)
    Customize the Default Field Filter Editor
    Create a Custom Field Filter Editor.

    Regards,
    Dimitrina
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  6. Ravin
    Ravin avatar
    16 posts
    Member since:
    Jun 2012

    Posted 19 Aug 2015 in reply to Dimitrina Link to this post

    Thanks, I did see the first link, but the second one helped me find a solution, I subscribed to the FieldFilterEditorCreated event, with the following method, which gave me the flexibility I was looking for:

    private void radGridView_FieldFilterEditorCreated(object sender, EditorCreatedEventArgs e)
    {
        RadDateTimePicker dateTimePickerEditor = e.Editor as RadDateTimePicker;
        if (dateTimePickerEditor != null)
        {
            dateTimePickerEditor.InputMode = InputMode.DateTimePicker;
            dateTimePickerEditor.Culture = new CultureInfo("en-US");
            dateTimePickerEditor.Culture.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
            dateTimePickerEditor.Culture.DateTimeFormat.ShortTimePattern = "hh:mm:ss tt";
        }
    }

     

    Thanks!

Back to Top
DevCraft banner