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

[Solved] Filtering Multiple Items

2 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aaron Gravois
Top achievements
Rank 1
Aaron Gravois asked on 05 Mar 2010, 02:38 PM
I need to apply filtering for a column in my RadGrid.  The column is an int column, and the user must be able to filter multiple selections.  I want to do something like this:  select * from <table> where num in (X,Y,Z).

How can I get this filtering functionality?


EDIT:
I followed an example on http://www.telerik.com/help/aspnet-ajax/grdcustomoptionforfiltering.html to add custom filtering, and this is what I came up with.

 
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == RadGrid.FilterCommandName) 
        { 
            Pair filterPair = (Pair)e.CommandArgument; 
 
            switch (filterPair.Second.ToString()) 
            {                
                case "vendNum"
                    TextBox tbPattern = (e.Item as GridFilteringItem)["vendNum"].Controls[0] as TextBox; 
                    if (tbPattern.Text.Contains(",")) 
                    { 
                        string[] values = tbPattern.Text.Split(','); 
                        if (values.Length >= 2) 
                        { 
                            e.Canceled = true
                            StringBuilder newFilter = new StringBuilder(); 
                            for (int i = 0; i < values.Length; i++) 
                            { 
                                if (i == values.Length - 1) 
                                    newFilter.Append("([vendNum]='" + values[i] + "')" ); 
                                else 
                                    newFilter.Append("([vendNum]='" + values[i] + "') OR "); 
                            } 
                            if (RadGrid1.MasterTableView.FilterExpression == ""
                                RadGrid1.MasterTableView.FilterExpression = newFilter.ToString(); 
                            else 
                                RadGrid1.MasterTableView.FilterExpression = "((" + RadGrid1.MasterTableView.FilterExpression + ") AND (" + newFilter.ToString() + "))"
                            RadGrid1.Rebind(); 
                        } 
                    } 
                    break
                default
                    break
            } 
        } 
    } 

This is giving me an "Expression Expected" error when I try to filter that column.  Anyone have an idea as to why that is?

Thanks,
Aaron

2 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 10 Mar 2010, 12:18 PM
Hello Aaron,

To make sure that this exception is not raised, please set the .EnableLinqExpressions for the grid instance to false. Additionally, to see how to construct the filter expression for the control, please refer to the following article:

http://www.telerik.com/help/aspnet-ajax/grdoperatewithfilterexpression.html

the last section contains additional information on how to construct the expression, and how to include multiple clauses via the and/or operators.
I hope this information helps.

All the best,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Aaron Gravois
Top achievements
Rank 1
answered on 10 Mar 2010, 03:57 PM
Thanks a lot, Yavor.  Setting EnableLinqExpressions to false solved the problem.  Also, thanks for pointing me to that article...I completely missed it when looking through the API documentation.

Aaron
Tags
Grid
Asked by
Aaron Gravois
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Aaron Gravois
Top achievements
Rank 1
Share this question
or