DateTime filtering date only with custom format

12 posts, 0 answers
  1. Thomas
    Thomas avatar
    10 posts
    Member since:
    Jun 2015

    Posted 08 Jan Link to this post

    Hi,

    I have DateTime columns in my gridview.
    I will see the full date and time values with a custom format string yyyy-MM-dd HH:mm:ss.

    But I only want to filter for the date only, so I set the FilterMemberPath to the date value.

     

    <telerik:GridViewDataColumn Header="Start-Date"
                                IsCustomSortingEnabled="False"
                                DataMemberBinding="{Binding StartTime}"
                                FilterMemberPath="StartTime.Value.Date"
                                DataFormatString="{} {0:yyyy-MM-dd HH:mm:ss}" />

     

    I'm now able to filter for a specific date with equal to,

    but in the selection list of  containing entries the dates will be displayed with 12:00:00 AM time :-(

    How could I change the format of the filter string to yyyy-MM-dd?

    Many thanks for all help.

    Cheers,

      Thomas

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 13 Jan Link to this post

    Hi Thomas,

    Indeed, the default behavior of the Filtering control is to add a value for hours, minutes and seconds of the bound DateTime property. Unfortunately, there is no straightforward approach for achieving the desired behavior.

    An approach you could take is to work with the filtering events of the RadGridView and change the DataFormatString property. You can subscribe for the FilterOperatorsLoading event, which is fired every time the filtering control is opened. Eventually, use the Filtered event to switch the FormatString to the original one. This, however, would work only if some filtering has been applied and could be used in specific scenarios. 

    Regards,
    Stefan Nenchev
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Thomas
    Thomas avatar
    10 posts
    Member since:
    Jun 2015

    Posted 13 Jan Link to this post

    Hi Stefan,

    is it possible to get a demo Project from your side how I have to work with the events in the filter control?
    Or might it be easier to use a custom filter control?

    Best regards,
      Thomas

  5. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 13 Jan Link to this post

    Hi Thomas,

    I have investigated the issue further and managed to come up with a better approach. It includes changing the CellTemplate of the specific column. Please refer to the following code snippet:

    <telerik:GridViewDataColumn DataMemberBinding="{Binding Established.Date}"
      Header="Est."
      DataFormatString="{}{0:yyyy-MM-dd}">
                       <telerik:GridViewDataColumn.CellTemplate>
                           <DataTemplate>
                               <TextBlock Text="{Binding Established, StringFormat={}{0:yyyy-MM-dd hh:mm:ss}}"/>
                           </DataTemplate>
                       </telerik:GridViewDataColumn.CellTemplate>
     </telerik:GridViewDataColumn>

    I have also attached a sample project implementing the suggested approach.

    Regards,
    Stefan Nenchev
    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. Thomas
    Thomas avatar
    10 posts
    Member since:
    Jun 2015

    Posted 14 Jan Link to this post

    Hi Stefan,

    this feels much better :-)
    As I have a nullable DateTime property I have to Change the DataMemberBinding to StartTime.Value.Date as I will loose the filtering Icon in other case.
    One Problem still exists. In the two fields of the date selection I still have a different Format. This field seems not to follow the DataFormatString :-(

    Is there a way too change this as well?

    Many thanks,

      Thomas

  7. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 14 Jan Link to this post

    Hi Thomas,

    You need to change the CurrentCulture of your application. The RadDateTimePicker uses that Culture in order to parse the input date and time.

    Please try the following approach:
               
                InitializeComponent();
                var culture = new CultureInfo("en-US");
                var dtfInfo = new DateTimeFormatInfo
                {
                    ShortDatePattern = "yyyy-MM-dd",
                    ShortTimePattern = "HH:mm",
                    DateSeparator = "-"
                };
                culture.DateTimeFormat = dtfInfo;
                Thread.CurrentThread.CurrentCulture = culture;
                Thread.CurrentThread.CurrentUICulture = culture;

     You can find more information at the following article from our documentation page - How to Set Different Culture

    I have tested this approach and it seems to do the job. Please update me if everything is working as expected at your end as well.

    Regards,
    Stefan Nenchev
    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
  8. Thomas
    Thomas avatar
    10 posts
    Member since:
    Jun 2015

    Posted 14 Jan in reply to Stefan Nenchev Link to this post

    Hi Stefan,

    yes, that does it.

    Many thanks for your support,

    Best regards,

       Thomas

  9. Thomas
    Thomas avatar
    10 posts
    Member since:
    Jun 2015

    Posted 15 Jan Link to this post

    Hi Stefan,

    your approach work fine for the filtering, but will break the sorting as we now have not bind the times :-(

    Regards,

      Thomas

  10. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 15 Jan Link to this post

    Hello Thomas,

    Setting the SortMemberPath property of the column should do the job for you:
    SortMemberPath="Established"
     
    I have tested it and it is working as expected, as you can see in this video. Please try this at your end and update me.

    Regards,
    Stefan Nenchev
    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
  11. Thomas
    Thomas avatar
    10 posts
    Member since:
    Jun 2015

    Posted 18 Jan Link to this post

    Hi Stefan,

    I tried to set SortMemberPath="Established", but in my case this seems to disable sorting completly.

    Could it be a Problem that my StartTime is nullable?

    Thanks,

       Thomas

  12. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 19 Jan Link to this post

    Hello Thomas,

    In the video recorded I have set a nullable DateTime property and I am able to perform the sorting. I have attached the sample project once again so you can review it. Would it be possible for you to update this project so that it represents your setup? Eventually, you can create a ticket and send it over so I can have a more detailed look. 

    Regards,
    Stefan Nenchev
    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
  13. Thomas
    Thomas avatar
    10 posts
    Member since:
    Jun 2015

    Posted 19 Jan in reply to Thomas Link to this post

    Ups,

    I have to set the SortMemberPath to "StartTime" - grrr - now it works.

    Cheers,

      Thomas

Back to Top
UI for WPF is Visual Studio 2017 Ready