- Home
- Forum
- ASP.NET MVC
- How to initialize filtered columns in grid using MVC helpers
How to initialize filtered columns in grid using MVC helpers
.SortSettings(s => s.SortedColumns(Model.SortedColumns))
.FilterSettings(f => f.FilteredColumns(Model.FilteredColumns))
Query: how do you initialize the filtered columns using the MVC helpers?
We have analyzed the reported query and we have considered this query “Setting filteredColumns using MVC helpers” as a bug and a support incident has been created under your account to track the status of this issue. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
As of now, we can achieve your requirement by getting the filteredColumns from the server side and pushing it to the grid filterCollections in the Load event of the grid. Please refer the below code snippet.
|
<div style="margin-top:30px"> @(Html.EJ().Grid<object>("Grid") .Datasource(Model.data) .AllowFiltering() . . . . .PageSettings(page=>page.CurrentPage(3).PageSize(6).PageCount(5)) //for customizing the paging functionality .SortSettings(sort=>sort.SortedColumns(so=>so.Field("Freight").Add()))//for initial sorting .GroupSettings(group => group.ShowGroupedColumn(false).GroupedColumns(co => { co.Add("EmployeeID"); })) //for initial grouping . . . . .ClientSideEvents(eve=>eve.Load("load")) ) </div>
<script type="text/javascript"> //load event of the grid function load(args){ var filterData = @Html.Raw(Json.Encode(Model.FilteredColumns)); //get the filterCollections from the server side var filterOp; for(var i=0;i<filterData.length;i++){ switch(filterData[i].Operator){ //code to convert the filter operator case 0: filterOp = "startswith" break; . . . . } this.model.filterSettings.filteredColumns.push({ field: filterData[i].Field, operator: filterOp, value: filterData[i].Value, matchcase: filterData[i].MatchCase, predicate: filterData[i].Predicate }); //pushing the filter list from server side to the grid filterCollections } } |
Query: in the MVC helper FilteredColumn.Operator can be "FilterOperatorType.Equals", whereas in the javascript control it must be the string "equal" (without the s).
Since we have set the FilterOperatorType as Enum type, the corresponding string value would be serialized with the help of ‘StringEnumConverter’ JsonConverter. Once we have provided the support for FiltereredColumns under FilterSettings, you can use it directly under FilterSettings where the filterOperator will be serialized and processed within accordingly.
For your convenience, we have created a sample with the above workaround and the same can be downloaded from the below location.
Sample Link: http://www.syncfusion.com/downloads/support/forum/119942/ze/Sample-464094018
Please get back to us if you need any further assistance.
Regards
Ragavee U S
- 1 Reply
- 2 Participants
-
SB Scott Belina
- Aug 17, 2015 10:55 PM UTC
- Aug 18, 2015 10:05 AM UTC