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

Using logical operator OR between columns for filtering

3 Answers 163 Views
GridView
This is a migrated thread and some comments may be shown as answers.
bohebolo
Top achievements
Rank 1
bohebolo asked on 11 Jan 2013, 11:47 AM
Maybe this is not a common case, but we really need to achieve this.
I'm creating a custom control that use RadGridView as one of it's part.
Our control need filtering capability, and I'm doing it this way:

foreach (GridViewColumn column in _gridView.Columns)
{
    if ((column as GridViewBoundColumnBase).DataType == typeof(string))
    {
        IColumnFilterDescriptor columnDescriptor = column.ColumnFilterDescriptor;
        columnDescriptor.SuspendNotifications();
        columnDescriptor.FieldFilter.Filter1.Operator = FilterOperator.Contains;
        columnDescriptor.FieldFilter.Filter1.Value = keyword;
        columnDescriptor.ResumeNotifications();
    }
}

 
My question is how to create the filter that uses logical operator OR between columns?
Something like this:
Where column1 = xxx OR column2 = xxx

thanks

3 Answers, 1 is accepted

Sort by
0
bohebolo
Top achievements
Rank 1
answered on 15 Jan 2013, 02:16 AM
Maybe my question wasn't clear enough so let me re-phrase it.
I am creating a custom ComboBox, that uses RadGridView as it's popup part.
What I want to achieve is: when user type inside the ComboBox's textbox, then the popup will be shown up with RadGridView items already filtered based on textbox's text.
Everything are working well, except I don't know how to do filter in RadGridView that uses logical "OR" operator between it's columns.

Please take a look on attached picture.
I want to filter RadGridView items with something like this: WHERE roleCode='XX'  OR  roleName='XX'
What I got now by using above code is: WHERE roleCode='XX'  AND  roleName='XX'

How to filter RadGridView items using that logical "OR" operator ?
Any comments, suggestion, or references will be appreciated.

thanks
0
bohebolo
Top achievements
Rank 1
answered on 16 Jan 2013, 03:39 AM
Any idea anyone?
Does someone from Telerik can confirm if it's possible to achieve this or not?
If the answer is not, I can create an event and let the developer that uses the combobox (my custom control) to create a handler and do the filter with their own way.
But somehow I don't think it is a correct way, since it will give them more job to be done.

PS: I'm racing with the deadline, and now stuck only on this matter.
Please let me know if my question wasn't clear enough.

thanks & regards
0
bohebolo
Top achievements
Rank 1
answered on 16 Jan 2013, 05:19 AM
After digging Telerik online help, finally I found the solution.

if (_gridView.FilterDescriptors.Count > 0)
    _gridView.FilterDescriptors.Clear();
 
CompositeFilterDescriptor mainCompositeDescriptor = new CompositeFilterDescriptor();
mainCompositeDescriptor.LogicalOperator = FilterCompositionLogicalOperator.Or;
 
foreach (GridViewColumn column in _gridView.Columns)
{
    if ((column as GridViewBoundColumnBase).DataType == typeof(string))
    {
        FilterDescriptor descriptor = new FilterDescriptor();
        descriptor.Member = column.UniqueName;
        descriptor.Operator = FilterOperator.Contains;
        descriptor.Value = keyword;
        mainCompositeDescriptor.FilterDescriptors.Add(descriptor);
    }
}
 
_gridView.FilterDescriptors.Add(mainCompositeDescriptor);
Tags
GridView
Asked by
bohebolo
Top achievements
Rank 1
Answers by
bohebolo
Top achievements
Rank 1
Share this question
or