Completed
Last Updated: 10 Oct 2017 12:22 by ADMIN
ADMIN
Hristo
Created on: 04 Sep 2017 14:29
Category: GridView
Type: Bug Report
2
FIX. RadGridView - exception in the RadListFilterPopup when filtering nullable dates
How to reproduce: check the attached project

Workaround: create a custom RadListFilterPopup
public class MyRadListFilterPopup : RadListFilterPopup
    {
        public MyRadListFilterPopup(GridViewDataColumn dataColumn, bool groupedDateValues)
            : base(dataColumn, groupedDateValues)
        { }

        protected override void OnButtonOkClick(EventArgs e)
        {
            FilterOperator filterOperator = FilterOperator.IsEqualTo;

            IRadListFilterElement listFilterElement = (IRadListFilterElement)typeof(RadListFilterPopup).GetField("listFilterElement", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
            RadListFilterDistinctValuesTable selectedValues = listFilterElement.SelectedValues;

            switch (listFilterElement.SelectedMode)
            {
                case ListFilterSelectedMode.All:
                    filterOperator = FilterOperator.None;
                    break;
                case ListFilterSelectedMode.Null:
                    filterOperator = FilterOperator.IsNull;
                    break;
                case ListFilterSelectedMode.NotNull:
                    filterOperator = FilterOperator.IsNotNull;
                    break;
            }

            if (filterOperator != FilterOperator.IsEqualTo)
            {
                SetFilterOperator(filterOperator);
                this.ClosePopup(RadPopupCloseReason.CloseCalled);
            }
            else
            {
                CompositeFilterDescriptor compositeFilterDescriptor = new CompositeFilterDescriptor();
                compositeFilterDescriptor.PropertyName = this.DataColumn.Name;
                RadListFilterDistinctValuesTable distinctValues = this.GetDistinctValuesTable();
                string blanksKey = RadGridLocalizationProvider.CurrentProvider.GetLocalizedString(RadGridStringId.FilterMenuBlanks);
                bool blanks = selectedValues.Contains(blanksKey);
                if (selectedValues.Count > distinctValues.Count / 2 && !blanks)
                {
                    compositeFilterDescriptor.LogicalOperator = FilterLogicalOperator.And;

                    foreach (DictionaryEntry entry in distinctValues)
                    {
                        string key = (string)entry.Key;
                        if (string.IsNullOrEmpty(key))
                        {
                            key = blanksKey;
                        }

                        if (!selectedValues.Contains(key))
                        {
                            foreach (object value in (ArrayList)entry.Value)
                            {
                                FilterDescriptor descriptor;
                                if (value == DBNull.Value)
                                {
                                    descriptor = new FilterDescriptor(this.DataColumn.Name, FilterOperator.IsNotEqualTo, null);
                                }
                                else if (this.DataColumn is GridViewDateTimeColumn || this.DataColumn.DataType == typeof(DateTime) || this.DataColumn.DataType == typeof(DateTime?))
                                {
                                    descriptor = new DateFilterDescriptor(this.DataColumn.Name, FilterOperator.IsNotEqualTo, (DateTime?)value, false);
                                }
                                else
                                {
                                    descriptor = new FilterDescriptor(this.DataColumn.Name, FilterOperator.IsNotEqualTo, value);
                                }

                                compositeFilterDescriptor.FilterDescriptors.Add(descriptor);
                            }
                        }
                    }
                }
                else
                {
                    compositeFilterDescriptor.LogicalOperator = FilterLogicalOperator.Or;

                    foreach (DictionaryEntry entry in selectedValues)
                    {
                        foreach (object value in (ArrayList)entry.Value)
                        {
                            FilterDescriptor descriptor;
                            if (value == DBNull.Value)
                            {
                                descriptor = new FilterDescriptor(this.DataColumn.Name, FilterOperator.IsNotEqualTo, null);
                            }
                            else if (this.DataColumn is GridViewDateTimeColumn || this.DataColumn.DataType == typeof(DateTime) || this.DataColumn.DataType == typeof(DateTime?))
                            {
                                descriptor = new DateFilterDescriptor(this.DataColumn.Name, FilterOperator.IsEqualTo, (DateTime?)value, false);
                            }
                            else
                            {
                                descriptor = new FilterDescriptor(this.DataColumn.Name, FilterOperator.IsEqualTo, value);
                            }

                            compositeFilterDescriptor.FilterDescriptors.Add(descriptor);
                        }
                    }
                }

                this.FilterDescriptor = compositeFilterDescriptor;
                OnFilterConfirmed();
            }
        }
    }
0 comments