Hi,
Im using a custom filter and want to use my own filter function (wanted to use wildcard options like * and ?), I followed the indications of this link: http://www.telerik.com/help/aspnet-ajax/grid-custom-option-for-filtering.html and the custom filter works.
Nevertheless the grid keeps the previous filter values I used before, I mean, if I used the value "test*" for the name column it gets all the rows that the name starts with "test" but if I change the filter value and hit enter, the MasterTableView.FilterExpression value keeps the value of the filter I used before
Here is my code
aspx
c#
For instance, this is the value the grid is using after a couple of filter changes, the first value was 2010* and the second was *annu*.
MasterTableView.FilterExpression = "(((([EventName] LIKE '2010%'))) AND ((([EventName] LIKE '%annu%'))))"
I if clear the filter textbox, hit enter and then enter the new filter value it does clear the MasterTableView.FilterExpression value
Thanks
Im using a custom filter and want to use my own filter function (wanted to use wildcard options like * and ?), I followed the indications of this link: http://www.telerik.com/help/aspnet-ajax/grid-custom-option-for-filtering.html and the custom filter works.
Nevertheless the grid keeps the previous filter values I used before, I mean, if I used the value "test*" for the name column it gets all the rows that the name starts with "test" but if I change the filter value and hit enter, the MasterTableView.FilterExpression value keeps the value of the filter I used before
Here is my code
aspx
<
asp:SqlDataSource
ID
=
"ds"
SelectCommand
=
"SELECT * FROM table"
runat
=
"server"
></
asp:SqlDataSource
>
<
telerik:RadGrid
ID
=
"grd"
runat
=
"server"
DataSourceID
=
"ds"
AutoGenerateDeleteColumn
=
"false"
AllowAutomaticDeletes
=
"true"
AllowFilteringByColumn
=
"True"
OnInit
=
"RadGrid_Init"
AllowMultiRowSelection
=
"true"
OnItemCreated
=
"RadGrid_ItemCreated"
OnItemCommand
=
"RadGrid_ItemCommand"
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
></
Selecting
>
<
ClientEvents
OnRowSelected
=
"Grid_RowSelected"
OnRowDeselected
=
"Grid_RowDeselected"
/>
</
ClientSettings
>
<
MasterTableView
ClientDataKeyNames
=
"ID"
AutoGenerateColumns
=
"False"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Name"
HeaderText
=
"Event Name"
CurrentFilterFunction
=
"Custom"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"false"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Year"
HeaderText
=
"Event Year"
CurrentFilterFunction
=
"EqualTo"
AutoPostBackOnFilter
=
"true"
ShowFilterIcon
=
"false"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
c#
protected void RadGrid_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName)
{
Pair filterPair = (Pair)e.CommandArgument;
if (filterPair.First.ToString() != "EqualTo")
{
string colName = filterPair.Second.ToString();
TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;
string value = tbPattern.Text;
if (value != string.Empty)
{
e.Canceled = true;
string newFilter = string.Empty;
if (value.IndexOf("*") >= 0) newFilter = "(([" + filterPair.Second + "] LIKE '" + value.Replace("*","%") + "'))";
else if (value.IndexOf("?") >= 0) newFilter = "(([" + filterPair.Second + "] LIKE '" + value.Replace("?", "%") + "'))";
else newFilter = "(([" + filterPair.Second + "] ='" + value + "'))";
if (grd.MasterTableView.FilterExpression == "")
{
grd.MasterTableView.FilterExpression = newFilter;
}
else
{
grd.MasterTableView.FilterExpression = "((" + grd.MasterTableView.FilterExpression + ") AND (" + newFilter + "))";
}
grd.Rebind();
}
}
}
}
For instance, this is the value the grid is using after a couple of filter changes, the first value was 2010* and the second was *annu*.
MasterTableView.FilterExpression = "(((([EventName] LIKE '2010%'))) AND ((([EventName] LIKE '%annu%'))))"
I if clear the filter textbox, hit enter and then enter the new filter value it does clear the MasterTableView.FilterExpression value
Thanks