Hi,
We want to implement custom filter "Contains" for template column (numeric). If we apply a filter on this column it is working fine. If we apply any other filter followed by custom filter then the previous filter is not getting cleared. Filter expressions are keep on appending for the same column.
Eg. Say we have column C1 which is template column and contains numeric data. We want to implement "contains" filter option on this column as custom filter.
If we apply "EqulaTo" filter first on this column C1, it works. Now if we apply "Contains" filter (custom) on this column C1, it should reset the previous filter and should apply new filter i.e. "Contains". But filter expressions keep on appending for this column and thus we don't get any result set. Following is the sample code snippet for the same implementation. We have included this in grid_ItemCommand event.
Please guide us ASAP.
We want to implement custom filter "Contains" for template column (numeric). If we apply a filter on this column it is working fine. If we apply any other filter followed by custom filter then the previous filter is not getting cleared. Filter expressions are keep on appending for the same column.
Eg. Say we have column C1 which is template column and contains numeric data. We want to implement "contains" filter option on this column as custom filter.
If we apply "EqulaTo" filter first on this column C1, it works. Now if we apply "Contains" filter (custom) on this column C1, it should reset the previous filter and should apply new filter i.e. "Contains". But filter expressions keep on appending for this column and thus we don't get any result set. Following is the sample code snippet for the same implementation. We have included this in grid_ItemCommand event.
Please guide us ASAP.
Pair filterPair = (Pair)e.CommandArgument;
if (filterPair.First.ToString() == "Custom")
{
string colName = filterPair.Second.ToString();
TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;
grid1.MasterTableView.GetColumn(colName).CurrentFilterFunction = GridKnownFunction.NoFilter;
e.Canceled = true;
string newFilter = @"it[" + colName + "].ToString().Contains(" + tbPattern.Text + ")";
if (grid1.MasterTableView.FilterExpression == "")
{
grid1.MasterTableView.FilterExpression = newFilter;
}
else
{
grid1.MasterTableView.FilterExpression = "((" + grid1.MasterTableView.FilterExpression + ") AND (" + newFilter + "))";
}
grid1.Rebind();
}