<div style="margin-top:20px;"> <button id="save">save</button> @(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .AllowScrolling() .AllowPaging() /*Paging Enabled*/ .ShowColumnChooser() .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Visible(false).Width(75).Add(); col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add(); }) .ClientSideEvents(eve => eve.Load("load"))) </div>
<script> function load(args) { var obj = $("#FlatGrid").ejGrid("instance"); var col = @(Html.Raw(Json.Encode(ViewBag.dataSource1))); $.each(col,function(index,value){ var obj1 = $("#FlatGrid").ejGrid("instance"); if(!value.visible){ for(i=0;i<obj1.model.columns.length;i++){ if( obj1.model.columns[i].field == value.field){ obj1.model.columns[i].visible = false; } } } }) } $("#save").click(function(){ var obj2 = $("#FlatGrid").ejGrid("instance"); var colList=[]; for(var i=0;i<obj2.model.columns.length;i++) colList.push({field:obj2.model.columns[i].field,visible:obj2.model.columns[i].visible}); $.ajax({ url: '/Grid/Save', type: 'POST', data:JSON.stringify({ "value":colList}), dataType: "json", contentType: "application/json; charset=utf-8", success: function (data) { } })
}); </script> |
<script> $("#save").click(function(){ var obj2 = $("#FlatGrid").ejGrid("instance"); var colList=[]; for(var i=0;i<obj2.model.columns.length;i++) colList.push({field:obj2.model.columns[i].field,visible:obj2.model.columns[i].visible}); $.ajax({ url: '/Grid/Save', type: 'POST', data:JSON.stringify({ "value":colList}), dataType: "json", contentType: "application/json; charset=utf-8", success: function (data) { } })
}); public ActionResult Save(List<ColumnDetails> value) { //here you can perform save operations |