[index.cshtml]
<button id='change' onclick="handleClick()"> PersistData</button>
<ejs-grid id="Grid" allowPaging="true" hieght="100%" allowReordering="true" allowFiltering="true" allowGrouping="true" >
<e-data-manager url="/Home/UrlDataSource" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="100"></e-grid-column>
. . . .
</e-grid-columns>
</ejs-grid>
</div>
<script type="text/javascript">
function handleClick() {
var gridInst = document.getElementsByClassName("e-grid")[0].ej2_instances[0];
var persistData = gridInst.getPersistData();
var ajax = new ej.base.Ajax;
ajax.url = "/Home/GetPersistData";
ajax.type = 'POST',
ajax.contentType = "application/json; charset=utf-8";
ajax.data = persistData;
ajax.send().then(function (args) {
var data = new ej.data.DataUtil.parse.parseJson(args);
console.log(data);
});
}
</script> |
[index.cshtml]
<div>
<button id='chan' onclick="setPersistDate()"> PersistData</button>
<button id='change' onclick="getPersistData()"> GetPersistData</button>
<ejs-grid id="Grid" allowPaging="true" hieght="100%" allowReordering="true" allowFiltering="true" allowGrouping="true">
<e-data-manager url="/Home/UrlDataSource" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-columns>
. . . .
</e-grid-columns>
</ejs-grid>
</div>
<script type="text/javascript">
// In this method pass the persist data to server method(PersistData)
function setPersistDate() {
var gridInst = document.getElementsByClassName("e-grid")[0].ej2_instances[0];
var persistData = gridInst.getPersistData();
var ajax = new ej.base.Ajax;
ajax.url = "/Home/PersistData";
ajax.type = 'POST',
ajax.contentType = "application/json; charset=utf-8";
ajax.data = persistData;
ajax.send();
}
// Following method get the persist data from server method(GetPersistData)
function getPersistData() {
var ajax = new ej.base.Ajax;
ajax.url = "/Home/GetPersistData";
ajax.type = 'POST',
ajax.contentType = "application/json; charset=utf-8";
ajax.send().then(function (args) {
var data = new ej.data.DataUtil.parse.parseJson(args);
gridInst.setProperties(data[0]);
console.log(data);
});
}
</script> |