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

Custom Filter option for template column

2 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shweta
Top achievements
Rank 1
Shweta asked on 03 Dec 2012, 02:39 PM
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.
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();
 
                }

2 Answers, 1 is accepted

Sort by
0
Mayur
Top achievements
Rank 1
answered on 04 Dec 2012, 10:59 AM

Hi,

We are facing the similar issue. Appreciate quick response !


Regards,
Mayur
0
Maria Ilieva
Telerik team
answered on 06 Dec 2012, 12:25 PM
Hello,

I would suggest you to refer to the help topic below which demonstrates the proper approach for achieving the required functionality:
http://www.telerik.com/help/aspnet-ajax/grid-custom-filter-options-with-handling.html

Test it on your end and let me know if it covers your requirements.

Greetings,
Maria Ilieva
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
Shweta
Top achievements
Rank 1
Answers by
Mayur
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or