Hi
I would like to have a custom button in the column header to reset the current filter value. I did this by creating a custom command ResetFilter, with the UniqueName as CommandArgument and some logic on ItemCommand.
But I would like to use the regular grid mechanic, a button with the CommandName Filter and ComandArgument Pair("NoFilter", UniqueName). How is this achieved? I just end up with an exception of string could not be cast to System.Web.UI.Pair.
Thanks!
I would like to have a custom button in the column header to reset the current filter value. I did this by creating a custom command ResetFilter, with the UniqueName as CommandArgument and some logic on ItemCommand.
But I would like to use the regular grid mechanic, a button with the CommandName Filter and ComandArgument Pair("NoFilter", UniqueName). How is this achieved? I just end up with an exception of string could not be cast to System.Web.UI.Pair.
Thanks!
5 Answers, 1 is accepted
0

Elliott
Top achievements
Rank 2
answered on 25 Oct 2011, 06:45 PM
could this snippet be what you are looking for?
it is in the click event of a Clear All Filters button
rgEditOrder.MasterTableView.FilterExpression =
string
.Empty;
rgEditOrder.Rebind();
0

Elliott
Top achievements
Rank 2
answered on 25 Oct 2011, 06:48 PM
to clear a single filter -
it returns the current filter with the filter for columnname cleared
private
string
RemoveFilter(
string
columnName)
{
string
filterExpression;
string
[] filterArray;
string
charac =
"&"
;
char
[] amper = charac.ToCharArray();
StringBuilder sb;
int
i;
sb =
new
StringBuilder(
""
);
filterExpression = rgEditOrder.MasterTableView.FilterExpression;
filterExpression = filterExpression.Replace(
" AND "
, charac);
filterArray = filterExpression.Split(amper, 3);
for
(i=0; i < filterArray.Length;i++)
{
if
(filterArray[i].IndexOf(columnName) == -1)
{
if
(sb.Length > 0)
{
sb.Append(charac);
}
sb.Append(filterArray[i]);
}
}
filterExpression = sb.ToString();
filterExpression = filterExpression.Replace(charac,
" AND "
);
return
filterExpression;
}
it returns the current filter with the filter for columnname cleared
0

Softec
Top achievements
Rank 1
answered on 26 Oct 2011, 01:06 PM
This is much more complicated than my solution. I don't like to fiddle with the filter expression by hand/stringbuilder.
What I did:
What I did:
But for this I have to know the Column UniqueName to set it as CommandArgument.void
TypedGrid_ItemCommand(
object
source, telerik.GridCommandEventArgs e)
{
switch
(e.CommandName)
{
case
(Grid.ResetFilterCommandName):
{
telerik.GridFilteringItem filterItem = e.Item
as
telerik.GridFilteringItem;
if
(filterItem !=
null
)
{
filterItem.FireCommandEvent(Grid.FilterCommandName,
new
ui.Pair(telerik.GridKnownFunction.NoFilter.ToString(), e.CommandArgument));
}
}
break
;
}
}
0

Elliott
Top achievements
Rank 2
answered on 26 Oct 2011, 09:43 PM
I just cut and paste a method which I used-
to build the filter this code worked:
so,do a text search for the first "([" then the UniqueName will be the string until the "]"
then look for the ")" then if there is an AND repeat
to build the filter this code worked:
filterExpression =
"([ShipDate] = '"
+ cmbShipDate.SelectedItem.Text +
"')"
;
then look for the ")" then if there is an AND repeat
0

Elliott
Top achievements
Rank 2
answered on 27 Oct 2011, 02:34 PM
get the DataSetIndex property on the DataItem
then go to the MasterTableView of the grid and the column by that index-you'll need to know what kind of grid column it is
then get the UniqueName of that column
not sure if this works for templated columns
then go to the MasterTableView of the grid and the column by that index-you'll need to know what kind of grid column it is
then get the UniqueName of that column
not sure if this works for templated columns