RadGridView ColumnFilterDescriptor in OR?

2 posts, 0 answers
  1. Michele
    Michele avatar
    426 posts
    Member since:
    Jun 2009

    Posted 07 Dec 2012 Link to this post

    Hello,
    I need to programmatically filter on a string field,that has values comma separated, for example

    a1,b2,c4,d5

    I adds the filter asn item is added to a custom object I've created my code is

    public void FilteringItemAdded(IF.UserControls.ItemAddedEventArg eventArgs)
           {
               if (radGridView == null) return;
     
               if (radGridView.Columns["Tags"] == null) return;
     
               GridViewColumn cityColumn = this.radGridView.Columns["Tags"];
     
               IColumnFilterDescriptor columnDescriptor = cityColumn.ColumnFilterDescriptor;
     
               columnDescriptor.SuspendNotifications();
               columnDescriptor.DistinctFilter.AddDistinctValue(eventArgs.ItemAdded.Name);
               columnDescriptor.ResumeNotifications();
     
               var lst = columnDescriptor.DistinctFilter.FilterDescriptors;
     
               foreach (FilterDescriptor q in lst)
               {
                   q.Operator = FilterOperator.Contains; //this is since I don't know how to directly a filtrer of tpye contains
               }
           }

    my problem is that if I've

    item1 | a1,b2,c4
    item2 |
    item3 | b2

    If I set first b2 I only have Item1 and Item3, when I add the tag "a1"  I don't have only item1 ... I think because the single distinct filter are matched in OR clause...is there a way of using them in AND?

    Thanks
    Paolo
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2477 posts

    Posted 07 Dec 2012 Link to this post

    Hi,

    I am afraid that there is no way to change the operator from OR to AND and that is by design. Distinct values are always OR'ed. You can develop your own custom ColumnFilterDescriptor that will generate the LINQ expression that you need.

    I have attached a sample project which might give you ideas how to build your custom column filter descriptor. Please, examine it carrefully, since your task is somewhat similar, i.e. read what the user has entered in the UI and then based on that information -- create a filtering LINQ expression.

    Kind regards,
    Rossen Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top