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

Initial Conditional Filtering

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alan Wong
Top achievements
Rank 1
Alan Wong asked on 14 Nov 2011, 07:30 PM
The examples for the MVC grid show how to provide a filter initially:
Html.Telerik().Grid(Model)
   
.Name("Grid")
   
.Filterable(filtering => filtering.Filters(filters =>
   
{
       
filters.Add(o => o.ContactName).StartsWith("Paul").And().EndsWith("Wilson");
   
}))

How could this be conditionally done, so that based on a view value, include or not this filter.

1 Answer, 1 is accepted

Sort by
0
Alan Wong
Top achievements
Rank 1
answered on 14 Nov 2011, 08:49 PM
For those who need to do this, I came up with this solution:

 

@{
    string filterName = Request.QueryString["InitialFilter"];
     
    var gridFilter = new System.Action<GridFilterDescriptorFactory<UserModelWithClientAndRole>>(filter => filter.Add(m => m.LastName).IsNotEqualTo(""));
    switch (filterName)
    {
        case "Active":
            gridFilter = filter => filter.Add(m => m.AccountDisabled).IsEqualTo(false);
            break;           
             
        case "Disabled":
            gridFilter = filter => filter.Add(m => m.AccountDisabled).IsEqualTo(true);
            break;
 
        case "Locked":
            gridFilter = filter => filter.Add(m => m.AccountLocked).IsEqualTo(true);
            break;
 
        case "Unregistered":
            gridFilter = filter => filter.Add(m => m.IsRegistered).IsEqualTo(false);
            break;           
    }
 
}


 

Then:

.Filterable(filtering => filtering.Filters(gridFilter))
Tags
Grid
Asked by
Alan Wong
Top achievements
Rank 1
Answers by
Alan Wong
Top achievements
Rank 1
Share this question
or