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

Filter with array of parameters

3 Answers 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roberto Wenzel
Top achievements
Rank 2
Roberto Wenzel asked on 02 Sep 2008, 04:33 PM
Hi, I would like to filter my GridView programmatically.
How do I use an array of search paramters.
Let's say I have a text array with 3 or for text strings and I want to filter one or more columns for these strings.
The result should be all rows where one ore more of my search strings is contained.
Thank you for a code snippet in vb.
Cheers Roberto

3 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 03 Sep 2008, 08:43 AM
Hi Roberto Wenzel,

You can filter the values for a column in the way that you want by adding filter predicates for each value like:
 
string[] filterParams = new string[] { "Ber""Ca" }; 
            FilterExpression filter = new FilterExpression(); 
            foreach (string filterParam in filterParams) 
            { 
                filter.Predicates.Add(FilterExpression.BinaryOperation.OR, GridKnownFunction.StartsWith, filterParam); 
            } 
 
            this.radGridView1.Columns["City"].Filter = filter; 

In a similar way you can add filter expressions for all the columns you need.

To show all rows where one or more columns satisfy the filter expression for that column you can combine the filter expressions with the OR operator like:

filter.BinaryOperator = FilterExpression.BinaryOperation.OR;

Kind regards,
Jordan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Roberto Wenzel
Top achievements
Rank 2
answered on 03 Sep 2008, 04:12 PM

Hello and thank you for the code example. But I need some more help implementing that code.
I am trying to to filter two columns with an OR operation.
Let's assume the following GridView:

            Col1     Col2
Row1     x         x
Row2     y         z

When my search array contains ("x", "y") I expect as result set Row1 and Row2.

Your code works fine when filtering/searching only one column.
For filtering two columns I tried following code, which does not work properly:

Dim fe As New FilterExpression
Dim fe1 As New FilterExpression
Dim i As Integer
        If ary.Length > 0 Then
            For i = 0 To UBound(ary)
                fe.Predicates.Add(FilterExpression.BinaryOperation.OR, GridKnownFunction.Contains, ary(i))
                fe.Parameters.Add(GridFilterCellElement.ParameterName, ary(i))
                fe1.Predicates.Add(FilterExpression.BinaryOperation.OR, GridKnownFunction.Contains, ary(i))
                fe1.Parameters.Add(GridFilterCellElement.ParameterName, ary(i))
            Next

        End If

        Me.gvMessages.Columns("ResolvedValue").Filter = fe
        Me.gvMessages.Columns("MessageValue").Filter = fe1

The result for search array ("x","y") is just Row1, because value "x" is in both columns.
fe and fe1 seem to be connected with an AND operation. What I need is an OR operation.
Maybe it is not possible to do what I like by default. In that case I need another approach, like iterating through all cells and highlight the found text or mark the cell with another background color or something like that.
Maybe you have another idea?
Cheers Roberto

0
Jordan
Telerik team
answered on 05 Sep 2008, 11:20 AM
Hi Roberto Wenzel,

Looking at your code it seems that the predicates are OK. However it is not clear how you create the filter expressions.

Did you try setting the binary operator of the second filter expression to OR like:
fe1.BinaryOperator = FilterExpression.BinaryOperation.OR;

If that does not work I will need the code that creates the filter expressions, so that I can reproduce your complete scenario locally.

Best wishes,
Jordan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Roberto Wenzel
Top achievements
Rank 2
Answers by
Jordan
Telerik team
Roberto Wenzel
Top achievements
Rank 2
Share this question
or