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

customize filter so that it'll filter according to predefined string

1 Answer 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 18 May 2012, 03:03 PM
Hi,

I was trying to customize a filter so that it'll filter the grid according to a predefined string. I was looking for a way to work around the issue of filtering a string that contains special characters.

basically, if the user select a filter with a name of "greater"...then it'll return all items that has the value ">130hp"...otherwise, if a user select a filter with a name of "less"....then it'll return all items that has the value "<130hp"

the following contains my initial code...copied and modified from the telerik documentation. Any assistance is welcome.


protected

 

 

void GridChevronPortEQ_ItemCommand(object sender, GridCommandEventArgs e)

 

{

 

 

if (e.CommandName == RadGrid.FilterCommandName)

 

{

 

 

Pair filterPair = (Pair)e.CommandArgument;

 

 

 

if (filterPair.First.ToString() == "greater")

 

{

 

 

string colName = filterPair.Second.ToString();

 

 

 

TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;

 

 

 

string[] values = tbPattern.Text.Split(' ');

 

 

 

if (values.Length == 2)

 

{

e.Canceled =

 

true;

 

 

 

string newFilter = "(([" + filterPair.Second + "] >='" + values[0] + "') AND ([" + filterPair.Second + "] <='" + values[1] + "'))";

 

 

 

if (GridChevronPortEQ.MasterTableView.FilterExpression == "")

 

{

GridChevronPortEQ.MasterTableView.FilterExpression = newFilter;

}

 

 

else

 

{

GridChevronPortEQ.MasterTableView.FilterExpression =

 

"((" + GridChevronPortEQ.MasterTableView.FilterExpression + ") AND (" + newFilter + "))";

 

}

GridChevronPortEQ.Rebind();

}

}

}

}

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 23 May 2012, 11:07 AM
Hello Minh,

You could achieve your scenario by following the practices shown and described in the demo and help articles below:

Regards,
Antonio Stoilkov
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.
Tags
Grid
Asked by
Minh
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or