<button id="btn"></button>
@(Html.EJ().Grid<object>("Grid")
...
.AllowReordering()
.Columns(col =>
{
col.Type("checkbox").Width(75).Add();
...
}))
<script>
$(function () {
$("#btn").ejButton({
text: "reorder columns",
click: function (args) {
var grid = $(".e-grid").ejGrid("instance");
grid.reorderColumns(0, 2); // reorder the columns using index
}
})
})
</script> |
<input type="button" id="restore" value="ResetColumns" />
<input type="button" value="unobtrusive" onclick="uClick()" />
@(Html.EJ().Grid<OrdersView>("FlatGrid")
.Datasource((IEnumerable<OrdersView>)ViewBag.datasource)
.AllowReordering()
.AllowPaging()
.EnablePersistence()
.ClientSideEvents(e=>e.Load("onLoad"))
.Columns(col =>
{
. . .
})
)
function onLoad(args) {
if (window.localStorage.getItem("Columns") == null)
window.localStorage.setItem("Columns", JSON.stringify(this.model.columns));//store the grid Original ordered columns in local storage variable while initial rendering
}
|
$("#restore").ejButton({
click: function () {
var gridModel = JSON.parse(window.localStorage.$ej$ejGridFlatGrid); //get the grid Model
gridModel.columns = JSON.parse(window.localStorage.getItem("Columns")); // get the initial grid columns from local storage and assign into gridmodel which is previously stored in the create event
$("#FlatGrid").ejGrid(gridModel);//rerender the grid which is intially loaded columns
}
})
|
input type="button" value="unobtrusive" onclick="uClick()" />
@(Html.EJ().Grid<OrdersView>("FlatGrid")
... .AllowReordering()
.AllowPaging()
.EnablePersistence()
.Columns(col =>
{
. . .
})
)
<script type="text/javascript">
. . .
function uClick() {
var grid = $("#FlatGrid"); //GridID
var gridObj = grid.ejGrid("instance");//Grid Instance
var originalColumns = grid.data("ej-columns");
var gridModel= JSON.parse(window.localStorage.$ej$ejGridFlatGrid)
gridModel.columns = originalColumns;
$("#FlatGrid").ejGrid(gridModel);
} |