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

[Solved] Multiple Custom Filters don't work together

1 Answer 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kristopher
Top achievements
Rank 1
Kristopher asked on 10 Aug 2013, 04:32 PM
Hi, I have a rad grid with some custom filters (multi-select drop down boxes).  I also have some custom filters which are boolean drop down types.  When I use the regular filters and then the custom filter, it will filter by the regular filters, and then filter by the custom filter.  But if I use the custom filter first and then any of the other filters, it wipes out all of the filters.  I could fix this by not using a filter type of "Custom", but if I use the regular string filtering offered by the rad grid, it does the comparison:

     ["Column"] Like '%value%' 

when what I actually want (since it is a multi-select dropdown, whose filter expression evaluates to String1, String2, String3) is

     Value Like '%[Column]%' 

Any help is much appreciated:

Here is how I do the custom filtering:

       
protected void MarkPickListResultGrid_ItemCommand(object source, GridCommandEventArgs e)
     {
         if (e.CommandName == RadGrid.FilterCommandName)
         {
             ListResultGrid.MasterTableView.CurrentPageIndex = 0;
             string columnUniqueName = (e.CommandArgument as Pair).Second.ToString();
              
             GridFilterColumn column = ListResultGrid.MasterTableView.Columns.FindByUniqueNameSafe("Type") as GridFilterColumn;
 
             if ((e.CommandArgument as Pair).First.ToString() == "Custom")
             {
                 List<string> filters = column.CurrentFilterValue.Split(',').ToList();
                 var predicate = PredicateBuilder.False<PickListMark>();
                 foreach (string filter in filters)
                 {
                     predicate = predicate.Or(r => filter.Contains(r.MarkType.MarkTypeName));
                 }
                 ListResultGrid.MasterTableView.DataSource = PickListMark.Where(predicate.Compile()).ToList();
                 ListResultGrid.MasterTableView.Rebind();
                 return;
             }
             
              
         }
     }


Edit:  Would it be a better idea to treat them all as custom and loop through all the columns in the above function and apply all the columns to the predicate and then filter the results?  

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 15 Aug 2013, 06:47 AM
Hi Kristopher,

You can refer to the following post for a practical example of FilterExpression manipulation:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/multi-selection-radcombobox-for-filtering-grid.aspx#2351833

Hope this helps.

Regards,
Eyup
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Kristopher
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or