GridView excel like filtering for Date columns does not behave as expected

1 Answer 215 Views
GridView
John
Top achievements
Rank 1
John asked on 07 Dec 2021, 07:29 PM

When I use the excel like filters of equals, greater than, or greater than or equal to with date columns I find no matches. 

My DateTime values bound to the column have 00:00:00.0000 as the time component, like 9/30/2008 00:00:00.00000.  When I pick this date on the calendar control in the excel like filter popup it works fine, but if I pick Available Filters -> Equals (or greater than, or greater than or equal to) and enter 9/30/2008 then it does not match the 9/30/2008 00:00:00.00000 rows. 

I have tried this with FilteringMode = Date and FilteringMode = All, but it does not seem to make a difference.  It seems like equals etc. is comparing it to like 9/30/2008 00:00:01.00000 or something crazy like that. 

Is there something I can do to get these equals etc. filters working?

 

Using version 2021.2.615.40

John
Top achievements
Rank 1
commented on 09 Dec 2021, 01:03 PM

In your example, if I use the calendar control then the sequence works:

  1. Click the filter button
  2. Click Available filters
  3. Click Equals
  4. Click the calendar button in the value field
  5. Click on December 10, 2021

 But if I do not use the calendar control then it does not work. This sequence produces no results:

  1. Click the filter button
  2. Click Available filters
  3. Click Equals
  4. Click on the day component of the value field
  5. Type in 10
  6. Click OK

 

Another note (which does not seem to change this scenario so far), using Today instead of Now for your sample data reflects our scenario a bit better (zeros out the time component):

this.radGridView1.Rows.Add(i,"Row"+i,DateTime.Today.AddDays(i));

 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 10 Dec 2021, 07:53 AM

Hello, John, 

Thank you for the detailed steps. It seems that the difference in the second case is that I use the popup calendar, while you enter the date input directly without opening the drop down at all. In this case, I was able to observe the described undesired behavior. 

I have logged it in our feedback portal by creating a public thread on your behalf. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to use the following custom implementation for CompositeDataFilterForm:

        private void RadGridView1_CreateCompositeFilterDialog(object sender, GridViewCreateCompositeFilterDialogEventArgs e)
        {
            e.Dialog = new CustomCompositeDataFilterForm();
        }

        public class CustomCompositeDataFilterForm : CompositeDataFilterForm
        {
            protected override void OnClosing(CancelEventArgs e)
            {
                base.OnClosing(e);
                if (GridFilterCellElement.ValidateUserFilter(this.FilterDescriptor))
                {
                    CompositeFilterDescriptor cfd = this.FilterDescriptor as CompositeFilterDescriptor;
                    if (cfd != null)
                    {
                        foreach (FilterDescriptor fd in cfd.FilterDescriptors)
                        {
                            TrimTimePart(fd);
                        }
                    }
                    else
                    {
                        TrimTimePart(this.FilterDescriptor);
                    }
                   
                }
            }

            private void TrimTimePart(FilterDescriptor filterDescriptor)
            {
                CompositeFilterDescriptor cfd = filterDescriptor as CompositeFilterDescriptor;
                if (cfd != null)
                {
                    foreach (FilterDescriptor fd in cfd.FilterDescriptors)
                    {
                        TrimTimePart(fd);
                    }
                }
                else
                {
                    DateTime dateValue = DateTime.MinValue;
                    if (DateTime.TryParse(filterDescriptor.Value + "", out dateValue))
                    {
                        dateValue = dateValue.Date;
                       filterDescriptor.Value = dateValue;
                    }
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Dec 2021, 09:28 AM

Hello, John, 

Following the provided information, I have prepared a sample project to test the Excel-like filtering behavior for a GridViewDateTimeColumn. Indeed, using GridViewTimeFilteringMode.Date is an appropriate way to perform filtering in a GridViewDateTimeColumn considering only the date part of a DateTime. The attached gif file illustrates the achieved result. The same behavior is observed with the latest version as well. Am I missing something? Could you please specify the exact steps how to reproduce the problem? Feel free to modify the project in a way to reproduce the experienced issue and get back to me with it so I can investigate the precise case. Thank you in advance. 

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or