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

RadGrid Filter with AND and OR

3 Answers 405 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 1
Kenneth asked on 27 Nov 2012, 09:03 PM
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.
-Ken

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 30 Nov 2012, 04:35 PM
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.

Greetings,
Eyup
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.
0
Andy
Top achievements
Rank 1
answered on 20 May 2014, 11:08 PM
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 ")
     Next
End If
0
Eyup
Telerik team
answered on 23 May 2014, 07:18 AM
Hello Andy,

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

Regards,
Eyup
Telerik
 

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.

 
Tags
Grid
Asked by
Kenneth
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Andy
Top achievements
Rank 1
Share this question
or