@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging()
.AllowReordering()
.EditSettings(edit => { edit.AllowDeleting().AllowEditing().AllowEditOnDblClick(false); })
.ClientSideEvents(eve => eve.Create("create"))
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();
col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();
col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();
col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Format("{0:MM/dd/yyyy}").Add();
})
)
<script>
function create(args) {
var grid = $("#FlatGrid").ejGrid("instance");
var col = grid.model.columns;
$.each(col,function(index,value){
var obj1 = $("#FlatGrid").ejGrid("instance");
if(value){
var columnIndex = obj1.getColumnIndexByField(value.field) + 1;
var temp = obj1.getColumnByIndex(parseInt(index));
var column = obj1.getColumnByIndex(columnIndex);
if(columnIndex <= 4)
obj1.reorderColumns(column.field, temp.field);
}
})
}
</script>
|