RadGrid Filter with AND and OR

4 posts, 0 answers
  1. Kenneth
    Kenneth avatar
    1 posts
    Member since:
    Nov 2012

    Posted 27 Nov 2012 Link to this post

    Suppose I have a RadGrid, such as the one in your demo, here: http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filteringtemplatecolumns/defaultcs.aspx.

    If I type liz in the Contact name filter box, and select Contains from the filter drop down, I get the three people in the list whose names contain the letters "liz". Pretty obvious.

    Now, if I type liz and lin in the Contact name filter box, and select Contains from the filter drop down, I get an empty list, because no names in the list contain the string "liz and lin". Also, not too surprising.

    But, if I type liz AND lin in the Contact name filter box (note the upper case AND), and select Contains from the filter drop down, the list contains the full set of names again. This also happens if I enter liz OR lin.

    It appears that the RadGrid is trying to treat the uppercase strings AND and OR as a boolean operator, failing, and then punting and returning the entire list. Whatever the reason, this is causing us problems. Our users tend to copy and paste stuff into the filter box, and it is often in upper case, and it sometimes has the word AND or OR in the copied string. This causes the application to behave unexpectedly for them, and leads to complaints.

    I haven't been able to find any way to turn this behavior off. Do you have any suggestions?

    Thanks for any help.
  2. Eyup
    Eyup avatar
    3296 posts

    Posted 30 Nov 2012 Link to this post

    Hello Kenneth,

    You could achieve that by removing the AND and OR statements from the forbidden filter string collection:
    protected void Page_Load(object sender, EventArgs e)
        GridFilterFunction.IllegalStrings = new string[] { " LIKE ", ">", "<", "<>", " NULL ", " IS " };
        RadGrid1.EnableLinqExpressions = false;

    Please note that this approach is not supported. An alternative approach would be to implement your custom filtering to meet your exact requirements.

    I hope this helps. Please give it a try and let me know about the result.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Andy
    Andy avatar
    2 posts
    Member since:
    Oct 2010

    Posted 20 May 2014 in reply to Eyup Link to this post

    I just encountered this problem and thought I'd share my expreience. If you just remove the illegal strings (as Eyup mentioned), it will try to parse whatever is after AND/OR as additional criteria rather than part of the value.

    Here is my solution (read: hack) in case it helps the next poor soul. First, as mentioned above, EnableLinqExpressions must be false.

    On request (i.e. Load or AjaxRequest) remove AND/OR from GridFilterFunction.IllegalStrings:

    'Remove AND\OR from Telerik's IllegalStrings to avoid conflicts with filter values
    GridFilterFunction.IllegalStrings = GridFilterFunction.IllegalStrings.Where(Function(s) s <> " AND " AndAlso s <> " OR ").ToArray()

    On ItemCommand, simply change the case of AND/OR so it is recognized as part of the value:

    If e.CommandName = RadGrid.FilterCommandName Then
         For Each column As GridColumn In grd.MasterTableView.Columns
              'Replace AND/OR to avoid conflict with Telerik's reserved keywords
              column.CurrentFilterValue = column.CurrentFilterValue.Replace(" AND ", " and ").Replace(" OR ", " or ")
    End If
  4. Eyup
    Eyup avatar
    3296 posts

    Posted 23 May 2014 Link to this post

    Hello Andy,

    Thank you for sharing your specific solution with the community. I hope it helps other developers with similar scenarios.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top