Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:07:16+00:00 2026-05-23T12:07:16+00:00

I want to save the state of a jqGrid (sortingcolumn, sortingorder, width of columns,

  • 0

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.

My first try was to load the data with the getGridParam 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:

$(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);
});

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 setGridParam method the grid have all default values. My code looks like the following:

$(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');
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:07:17+00:00Added an answer on May 23, 2026 at 12:07 pm

    This is how I saved the state of my Grid (as json data in a hidden field though instead of localstorage, but the idea should be the same).

    Saving the Grid Parameters as JSON in the hidden field:

     function saveGridParameters(grid) {       
                var gridInfo = new Object();
    
                gridInfo.url = grid.jqGrid('getGridParam', 'url');
                gridInfo.sortname = grid.jqGrid('getGridParam', 'sortname');
                gridInfo.sortorder = grid.jqGrid('getGridParam', 'sortorder');
                gridInfo.selrow = grid.jqGrid('getGridParam', 'selrow');
                gridInfo.page = grid.jqGrid('getGridParam', 'page');
                gridInfo.rowNum = grid.jqGrid('getGridParam', 'rowNum');
                gridInfo.postData = grid.jqGrid('getGridParam', 'postData');
                gridInfo.search = grid.jqGrid('getGridParam', 'search');
    
                $('#gridParams').val(JSON.stringify(gridInfo));
            }
    

    Loading the saved data: (I load the saved data in the beforeRequest event of the grid):

                    beforeRequest: function() //loads the jqgrids state from before save
                    {
                        if(gridParams !=null && gridParams!="")
                        {                            
                            var gridInfo = $.parseJSON(gridParams);                                    
                            var grid = $('#ReportPartsGrid');                           
    
                            grid.jqGrid('setGridParam', { url: gridInfo.url });
                            grid.jqGrid('setGridParam', { sortname: gridInfo.sortname });
                            grid.jqGrid('setGridParam', { sortorder: gridInfo.sortorder });
                            grid.jqGrid('setGridParam', { selrow: gridInfo.selrow });
                            grid.jqGrid('setGridParam', { page: gridInfo.page });
                            grid.jqGrid('setGridParam', { rowNum: gridInfo.rowNum });
                            grid.jqGrid('setGridParam', { postData: gridInfo.postData });
                            grid.jqGrid('setGridParam', { search: gridInfo.search });
    
                            gridParams = '';
                            $('#ReportPartsGrid').trigger('reloadGrid');                           
                        }                                               
                    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to save application state to be able to restore it after another
When I want to save some state behavior of the activity, The docs says
I have a Seekbar and I want to save the state to database when
I want save the username and password when user login, and I added the
I want to know how can I save state of my application in android.What
I want to save object state and reuse it after some time. I got
I want to save the state of my view controller. I searched and found
I create a bunch of forms, and I want to save and restore their
I'm making an iPhone app where I want to save state of the Application.
I want to save the state of a multiple choice listview checkbox's. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.