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

Complex filter

3 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tommy Savela
Top achievements
Rank 1
Tommy Savela asked on 07 Dec 2009, 09:21 AM
Hi,

I'm having a problem with creating a complex filter expression in RadGridView.

The scenario can be described like this:
I have a DataTable containing columns Name (string), Address (string) and Finished (bool).
I'm giving the user the possibility to do a freetext search in the grid, where the user enters a text in a textbox, and I apply filters on columns Name and Address using Contains(entered string).

The above works fine. However, the problem is that I also have a checkbox "Show finished" that should always filter the data on the "Finished" column. I'm not able to get the correct filter expression for this, since when I add the Finished filter it's added as an OR filter with the other columns.

So in total I want a filter in the GridView that is something like this:
Finished=0 AND (Name LIKE '%text%' OR Address LIKE '%text%')
but I'm only able to get:
Finished=0 OR Name LIKE '%text%' OR Address LIKE '%text%'

Is this currently possible to do in some way?

Regards,
Tommy Savela

3 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 09 Dec 2009, 12:00 PM
Hello Tommy Savela,

You can try with these expressions:

FilterExpression filterExpression = new FilterExpression("Finished", FilterExpression.BinaryOperation.AND, GridKnownFunction.EqualTo, true);
this.radGridView1.MasterGridViewTemplate.FilterExpressions.Add(filterExpression);
 
filterExpression = new FilterExpression("Name", FilterExpression.BinaryOperation.AND, GridKnownFunction.Contains, "text");
FilterExpression filterExpression3 = new FilterExpression("Address", FilterExpression.BinaryOperation.OR, GridKnownFunction.Contains, "text");
filterExpression.Combine(filterExpression3);
this.radGridView1.MasterGridViewTemplate.FilterExpressions.Add(filterExpression);


Best wishes,
Julian Benkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tommy Savela
Top achievements
Rank 1
answered on 09 Dec 2009, 02:28 PM
Thank you for the suggestion. However, it does not seem to be working.

When I use the suggested code (modified slightly, since the FilterExpression.Combine seems to return the combined expression instead of applying it to the object directly) as this:
 
filterExpression = new FilterExpression("Name", FilterExpression.BinaryOperation.AND, GridKnownFunction.Contains, "text");  
FilterExpression filterExpression3 = new FilterExpression("Address", FilterExpression.BinaryOperation.OR, GridKnownFunction.Contains, "text");  
filterExpression = filterExpression.Combine(filterExpression3); 

...the combined filterExpression does not seem to be valid. In the debugger the filterExpression shows up as an empty statement, but still contains several Predicates. When applied to the GridView the filter does nothing at all, so it does not seem to work correctly.

Any ideas?

0
Accepted
Nick
Telerik team
answered on 11 Dec 2009, 12:52 PM
Hi Tommy Savela,

Thank you for writing us back. Unfortunately there is not much to be done currently. Our current filtering expressions are combined in a list (not a tree) and this list does not support brackets (otherwise it would have been kind of a tree). The underlying expressions are actually strings and there you can use brackets to change the precedence, but this strings are not exposed in any way that you can circumvent the current limitation of the API. We will consider the available options and we will provide(expose) all the functionality of the filtering expressions in the next release (Q1 2010). Please excuse us for the introduced inconvenience.

As you have already noted the Combine method does not circumvent the limitation that you found as it simply add items linearly. 

I have updated your Telerik points for bringing this issue to our attention. I hope that otherwise your trial period is going fine.

Best wishes,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Tommy Savela
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Tommy Savela
Top achievements
Rank 1
Nick
Telerik team
Share this question
or