Hi Guys,
I have JQuery, KendoUI ASPNET MVC 5 which has two pages Index and View Details Page each has a dedicated js file and want to return to the previous Grid page number when a button in View Details is clicked:
- In the first page I search Customer details which populates a table with Customer details { Name, Occupation and Title, a link to the view details} and has pageSize of 10 and multiple pages, depending on the customers stored.
- What I want to achieve is to be able to return to the previous page results that was selected when and <a> to view details was clicked. For Instance I click <a> element on page number 20, I want to return to page 20 when I click save.
This is what I have tried so far:
- I used the standard way of saving the page grid in a sessionStorage , retrieving the saved page and assigning it to the current page when save or cancel button is clicked, and assigning the saved grid page number using this method: kendoGrid.dataSource.page(savedPage).
- Results: Returns to the first of results, irrespective of the current save page in the session storage.
I then attempted to fix the issue by trying to set the page number using the jquery.
ViewDetails.js
$(document).ready(function () {
$("button.isa-button-back, button.isa-button-save").click(function (e) {
localStorage.setItem("depositButtonClicked", true);
});
});
Index.js
$(document).ready(function () {
var filterNumber = $("span.k-state-selected").text();
localStorage.setItem("filterNumber", filterNumber);
if (localStorage.getItem("depositButtonClicked") === "true") {
var storedValue = localStorage.getItem("filterNumber");
$($("ul.k-pager-numbers li span.k-state-selected")).removeClass(
"k-state-selected"
);
$("ul.k-pager-numbers li span")
.filter(function () {
return $(this).text() == parseInt(storedValue);
})
.addClass("k-state-selected");
localStorage.removeItem("storedValue");
localStorage.removeItem("depositButtonClicked");
}
});
Results: Internal Server Error 500, when I click save or back button in the detailsPage
Another way that I tried was to use this function in the CustomerController's method:
public ActionResult Back()
{
SetScriptModuleOptions("IndexModule", new { RestoreGrid = true });
SetScriptModuleOptions("IsaSearchGrid", new { PreserveGridState = GridStatePreservation.All });
return RedirectToAction("Index");
}