I have a radgrid I am using to hold data about client interests likes and dislikes. I need the user to be able to filter the results. I was using radfilter, and it works, but is very complicated for the end user and is too confusing. I thought that the way it is set up in the rad grid itself may be easier.
Though from what I can tell, I can only do one expression at a time. I cannot do "and" and "or" expressions. Say I wanted to see who likes TV-Cartoon and who likes TV-Outdoors. Is there a way I can make BOTH of those appear?
As far as I can tell, you can only type one thing in the text box, use the filter drop down (I just used contains) and have that one expression show. Is there a way to do multiple?
8 Answers, 1 is accepted
The Excel-Like filtering functionality of the grid has the option to filter using multiple values (e.g. Value1 AND Value2). Please check out the Grid - Excel-like Filtering demo to see it in action.
Additionally you can check out the following articles that could be helpful to achieve the described behavior::
- Custom Filter Options with Handling
- Filter Template and Custom Columns
- Besides the built-in functionalities, you can also try to build/modify the filter expressions manually. Instructions are described in the Operate with the FilterExpression Manually
- Or modify the filter options: Custom Filter Options with Handling
Kind regards,
Attila Antal
Progress Telerik

I apologize, I have missed out one of the most important articles. That is the Header Context Menu. By getting familiar with the article, you will be able to change the HeaderContextMenu options and add/change/remove items as necessary.
Then you can use the custom filtering options/items in combination with the FilterCommand described in the Custom Filter Options with Handling you can apply any kind of filtering.
- Fire command Server-Side: https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/control-lifecycle/how-to-fire-command-events
- Fire command Client-Side: https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/gridtableview-object/methods/filter
Kind regards,
Attila Antal
Progress Telerik

Manipulating the FilterExpressions described in the Operate filter expressions article I've shared earlier may be an simpler approach. RadFilter does not even have to be used.
Create the Controls that will be used for filtering (similar to those from the picture you have shared)
<
telerik:RadLabel
ID
=
"RadLabel1"
runat
=
"server"
AssociatedControlID
=
"RadTextBox1"
Text
=
"ShipName Contains"
></
telerik:RadLabel
>
<
telerik:RadTextBox
ID
=
"RadTextBox1"
runat
=
"server"
Text
=
"3"
></
telerik:RadTextBox
>
<
telerik:RadLabel
ID
=
"RadLabel2"
runat
=
"server"
AssociatedControlID
=
"RadTextBox2"
Text
=
"OR"
></
telerik:RadLabel
>
<
telerik:RadTextBox
ID
=
"RadTextBox2"
runat
=
"server"
Text
=
"4"
></
telerik:RadTextBox
>
<
telerik:RadButton
ID
=
"RadButton1"
runat
=
"server"
Text
=
"Filter"
OnClick
=
"RadButton1_Click"
></
telerik:RadButton
>
<
br
/>
<
br
/>
<
telerik:RadLabel
ID
=
"RadLabel3"
runat
=
"server"
AssociatedControlID
=
"RadTextBox3"
Text
=
"ShipName Contains"
></
telerik:RadLabel
>
<
telerik:RadTextBox
ID
=
"RadTextBox3"
runat
=
"server"
Text
=
"1"
></
telerik:RadTextBox
>
<
telerik:RadLabel
ID
=
"RadLabel4"
runat
=
"server"
AssociatedControlID
=
"RadTextBox4"
Text
=
"AND"
></
telerik:RadLabel
>
<
telerik:RadTextBox
ID
=
"RadTextBox4"
runat
=
"server"
Text
=
"6"
></
telerik:RadTextBox
>
<
telerik:RadButton
ID
=
"RadButton2"
runat
=
"server"
Text
=
"Filter"
OnClick
=
"RadButton2_Click"
></
telerik:RadButton
>
<
br
/>
<
br
/>
<
telerik:RadButton
ID
=
"RadButton3"
runat
=
"server"
Text
=
"Clear"
OnClick
=
"RadButton3_Click"
></
telerik:RadButton
>
Create the Grid and set the AllowFilteringByColumn property to true to enable the filtering, and IsFilterItemExpanded property to false, to hide the Filter row.
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowFilteringByColumn
=
"true"
>
<
MasterTableView
IsFilterItemExpanded
=
"false"
>
</
MasterTableView
>
</
telerik:RadGrid
>
When clicking the Filter button of each filtering criteria:
Filter using Value1 "OR" Value2
protected
void
RadButton1_Click(
object
sender, EventArgs e)
{
if
(
string
.IsNullOrEmpty(RadTextBox1.Text) ||
string
.IsNullOrEmpty(RadTextBox2.Text))
return
;
StringBuilder filterExpression =
new
StringBuilder();
filterExpression.Append(
string
.Format(
"(it[\"ShipName\"].ToString().Contains(\"{0}\") OR it[\"ShipName\"].ToString().Contains(\"{1}\"))"
, RadTextBox1.Text, RadTextBox2.Text));
RadGrid1.MasterTableView.FilterExpression = filterExpression.ToString();
RadGrid1.Rebind();
}
Filter using Value1 "AND" Value2
protected
void
RadButton2_Click(
object
sender, EventArgs e)
{
if
(
string
.IsNullOrEmpty(RadTextBox3.Text) ||
string
.IsNullOrEmpty(RadTextBox4.Text))
return
;
StringBuilder filterExpression =
new
StringBuilder();
filterExpression.Append(
string
.Format(
"(it[\"ShipName\"].ToString().Contains(\"{0}\") AND it[\"ShipName\"].ToString().Contains(\"{1}\"))"
, RadTextBox3.Text, RadTextBox4.Text));
RadGrid1.MasterTableView.FilterExpression = filterExpression.ToString();
RadGrid1.Rebind();
}
Clear the Filter:
protected
void
RadButton3_Click(
object
sender, EventArgs e)
{
if
(!
string
.IsNullOrEmpty(RadGrid1.MasterTableView.FilterExpression)) RadGrid1.MasterTableView.FilterExpression =
string
.Empty;
RadGrid1.Rebind();
}
Attached you can find a WebForms page demonstrating this scenario. Please download and test sample to see if that is what you are looking for. The code is fully runnable, you can either import the page into a Web Site project or copy its source code.
Kind regards,
Attila Antal
Progress Telerik


I also should have been more specific. I do not want the same thing every time in the text boxes. Just the same set up, and filtering per line.
So one should be able to do:
individual likes __________(text box) OR ____________(text box) (button here)
and put whatever they need in each box. One time, it could be likes cats OR dogs. Another time, parrots OR pigs. The text boxes will change depending on what exactly they want to filter; the filtering itself (this or that) should stay prebuilt and the same. The possibility of interests will be a couple hundred long possibly. There is no way to guarantee that cats OR dogs would be a popular search every time the web form is loaded. But needing to filter by "anything" or "anything" is.
I apologize, I was not aware of your preferred coding language.
Below I will share the VB version of the code:
Protected
Sub
RadButton1_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
If
String
.IsNullOrEmpty(RadTextBox1.Text)
OrElse
String
.IsNullOrEmpty(RadTextBox2.Text)
Then
Return
Dim
filterExpression
As
StringBuilder =
New
StringBuilder()
filterExpression.Append(
String
.Format(
"(it["
"ShipName"
"].ToString().Contains("
"{0}"
") OR it["
"ShipName"
"].ToString().Contains("
"{1}"
"))"
, RadTextBox1.Text, RadTextBox2.Text))
RadGrid1.MasterTableView.FilterExpression = filterExpression.ToString()
RadGrid1.Rebind()
End
Sub
Protected
Sub
RadButton2_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
If
String
.IsNullOrEmpty(RadTextBox3.Text)
OrElse
String
.IsNullOrEmpty(RadTextBox4.Text)
Then
Return
Dim
filterExpression
As
StringBuilder =
New
StringBuilder()
filterExpression.Append(
String
.Format(
"(it["
"ShipName"
"].ToString().Contains("
"{0}"
") AND it["
"ShipName"
"].ToString().Contains("
"{1}"
"))"
, RadTextBox3.Text, RadTextBox4.Text))
RadGrid1.MasterTableView.FilterExpression = filterExpression.ToString()
RadGrid1.Rebind()
End
Sub
Protected
Sub
RadButton3_Click(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
If
Not
String
.IsNullOrEmpty(RadGrid1.MasterTableView.FilterExpression)
Then
RadGrid1.MasterTableView.FilterExpression =
String
.Empty
RadGrid1.Rebind()
End
Sub
The text for each textbox was pre-populated for testing purposes. You can remove them easily by removing the Text properties of each TextBox control.
Kind regards,
Attila Antal
Progress Telerik