Unplanned
Last Updated: 09 Dec 2021 14:57 by ADMIN
John
Created on: 09 Dec 2021 14:56
Category: GridView
Type: Bug Report
0
RadGridView: Missing rows after applying a date filter in Excel-like filtering

Use the following code snippet:

public RadForm1()
{
    InitializeComponent();

    GridViewDecimalColumn idColumn = new GridViewDecimalColumn("Id");
    this.radGridView1.Columns.Add(idColumn);
    GridViewTextBoxColumn nameColumn = new GridViewTextBoxColumn("Name");
    this.radGridView1.Columns.Add(nameColumn);
    GridViewDateTimeColumn dateColumn = new GridViewDateTimeColumn("Date");
    dateColumn.FilteringMode = GridViewTimeFilteringMode.Date;
    dateColumn.Format = DateTimePickerFormat.Custom;
    dateColumn.CustomFormat = "dd/MM/yyyy";
    dateColumn.FormatString = "{0:dd/MM/yyyy}";
    this.radGridView1.Columns.Add(dateColumn);
    this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

    for (int i = 0; i < 50; i++)
    {
        this.radGridView1.Rows.Add(i,"Row"+i,DateTime.Now.AddDays(i));
    }

    this.radGridView1.EnableFiltering = true;
    this.radGridView1.ShowHeaderCellButtons = true;
    this.radGridView1.ShowFilteringRow = false;

    this.radGridView1.FilterExpressionChanged += RadGridView1_FilterExpressionChanged;
}

private void RadGridView1_FilterExpressionChanged(object sender, FilterExpressionChangedEventArgs e)
{
    Console.WriteLine(e.FilterExpression);
}

 If I use the calendar control then the sequence works:

Click the filter button
Click Available filters
Click Equals
Click the calendar button in the value field
Click on December 10, 2021

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

Click the filter button
Click Available filters
Click Equals
Click on the day component of the value field
Type in 10
Click OK

Workaround:

        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;
                    }
                }
            }
        }

0 comments