This is a migrated thread and some comments may be shown as answers.

CompositeFilterExpression not filtering as expected

0 Answers 8 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Priyam
Top achievements
Rank 1
Priyam asked on 16 Jan 2014, 04:09 PM
I have a grid which has to be filtered programatically based on user entry. More than one column has to be filtered and each column may have more than 1 value to be filtered upon. Like say, Col1, Col2, Col7, Col8 has to be filtered on {1,4}, {1,38}, {78,65} & {1,0} respectively.

I have written the below code for this but looks like it filters only on the last set of values i.e. 4,38,65,0.

public static void SetGridFilterComposite(RadGridView gridView, Dictionary<string, List<int>> filterValues)
        {
            CompositeFilterDescriptor mainDescriptor = new CompositeFilterDescriptor();
            List<int> values = null;
 
            if (filterValues == null || filterValues.Count == 0) return;
 
            ClearGridFilterColumns(gridView);
 
            foreach (string column in filterValues.Keys)
            {
                CompositeFilterDescriptor columnDescriptor = new CompositeFilterDescriptor();
                if (gridView.Columns.Contains(column))
                {
                    values = filterValues[column];
                    FilterDescriptor filterDescriptor = new FilterDescriptor();
                    foreach (int value in values)
                    {
                        filterDescriptor.PropertyName = column;
                        filterDescriptor.Operator = FilterOperator.IsEqualTo;
                        filterDescriptor.Value = value;                       
                        columnDescriptor.FilterDescriptors.Add(filterDescriptor);
                    }
                    columnDescriptor.LogicalOperator = FilterLogicalOperator.Or;
                    mainDescriptor.FilterDescriptors.Add(columnDescriptor);
                }
            }
            mainDescriptor.LogicalOperator = FilterLogicalOperator.And;
            mainDescriptor.IsFilterEditor = true;
            gridView.FilterDescriptors.Add(mainDescriptor);
        }

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Priyam
Top achievements
Rank 1
Share this question
or