[index.cshtml]
<ejs-grid id="Grid" allowPaging="true" dataBound="onDataBound" recordDoubleClick="ejsGridDoubleClick" toolbar="@(new List<string>() {"Search" })">
<e-data-manager id="myData" url="/api/Orders" adaptor="WebApiAdaptor" crossDomain="true"></e-data-manager>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
<e-grid-column field="ShipCity" headerText="Ship City" width="170"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" template="<a>${ShipCountry}</a>" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
var selectIndx;
var flag = false;
function onDataBound(args) {
// Get the EJ2 Grid currentPageIndex, selection index and search string value from local storage
// you can also add conditions based on your requirement here
var currentPageIndex = parseInt(window.localStorage.getItem("pageIndex"), 10);
var selectedRowIndex = parseInt(window.localStorage.getItem("selectIndex"), 10);
var searchString = window.localStorage.getItem("searchString");
if ((selectedRowIndex && currentPageIndex == 1) || flag) {
selectIndx = selectedRowIndex ? selectedRowIndex : selectIndx;
this.selectRows([selectIndx]);
window.localStorage.removeItem("selectIndex"); // once set the selection index to grid then, we have reset the local storage
}
if (currentPageIndex) {
this.pageSettings.currentPage = currentPageIndex;
window.localStorage.removeItem("pageIndex");
flag = true;
}
if (searchString) {
this.search(searchString);
window.localStorage.removeItem("searchString");
}
}
function ejsGridDoubleClick(args) {
// Here, we have set the EJ2 Grid currentPageIndex, selection index and search string value to localstorage
window.localStorage.setItem("pageIndex", this.pageSettings.currentPage );
window.localStorage.setItem("selectIndex", args.rowIndex);
window.localStorage.setItem("searchString", this.searchSettings.properties.key);
if (window.location.rel='nofollow' href.split("Home").length > 1) {
window.location.rel='nofollow' href = window.location.rel='nofollow' href.split("Home")[0] + "Home" + "/About"
} else {
window.location.rel='nofollow' href = "Home/About"
}
}
</script> |