Using logical operator OR between columns for filtering

4 posts, 0 answers
  1. bohebolo
    bohebolo avatar
    31 posts
    Member since:
    Aug 2010

    Posted 11 Jan 2013 Link to this post

    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
  2. bohebolo
    bohebolo avatar
    31 posts
    Member since:
    Aug 2010

    Posted 14 Jan 2013 Link to this post

    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
  3. bohebolo
    bohebolo avatar
    31 posts
    Member since:
    Aug 2010

    Posted 15 Jan 2013 Link to this post

    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
  4. bohebolo
    bohebolo avatar
    31 posts
    Member since:
    Aug 2010

    Posted 15 Jan 2013 Link to this post

    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);
Back to Top