Note that there are some explanatory texts on larger screens.

plurals
  1. POSave state of jqGrid in localStorage after leaving the site
    primarykey
    data
    text
    <p>I want to save the state of a jqGrid (sortingcolumn, sortingorder, width of columns, toolbar searchfields), when the user leave the site and restore the grid when he comes back to the site. </p> <p>My first try was to load the data with the <code>getGridParam</code> method then serialize it with JSON and save it as JSON-String in a cookie. But a cookie have not enough space to save the gridParam. So I decided to use localstorage to save the state of the Grid. My code looks like this:</p> <pre><code>$(window).unload(function () { // Load GridParam var gridData = $('#Grid').jqGrid('getGridParam')}; // Serialize it to as JSON-String var gridDataAsString = $.toJSON(gridData); // Save the serialized Griddata in the localStorage localStorage.setItem("GridParam", gridDataAsString); }); </code></pre> <p>This works fine. But in the next step I load the GridParam from the localStroage and try to restore the grid.Loading the data is also no problem. In debugging mode I can see that all data are correctly loaded from the localStorage. But if I want to restore the Grid with the <code>setGridParam</code> method the grid have all default values. My code looks like the following:</p> <pre><code>$(document).ready(function () { $("#Grid").jqGrid({ /* Initialize the grid with default values */ }); var loadedGridDataAsString = localStorage.getItem("GridParam"); // Use the default value if no data exists in localStorage if (loadedGridDataAsString != null) { // Deserialize the JSON-String to an object var loadedGridData = $.evalJSON(loadedGridDataAsString); $("#Grid").jqGrid('setGridParam', loadedGridData); $("#Grid").trigger('reloadGrid'); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload