Results 1 to 6 of 6

Thread: Restore state of grid panel

  1. #1
    Sencha User
    Join Date
    Sep 2013
    Posts
    30
    Answers
    1

    Default Answered: Restore state of grid panel

    Using Ext JS 4.2 I am trying to make it so the state of the grid panel is saved from session to session. For example I want to be able to change the width of a column, refresh the page, and then still see the changed column width when the page reloads. Using the stateful property in the grid panel and the cookie provider I have been able to get it to save state when it is changed and I can see the changes when I reload the page. The only problem is that the state restore isn't getting called so the state is not getting restored.

    My understanding is that a stateful component is supposed to restore its last state in the constructor. Is this not the case? Do I have to actually have to restore the table myself using the information in the state manager?

  2. You create the viewport (and as such, the grid) before you create the cookie provider, so there's nothing to restore the state from.

  3. #2

  4. #3
    Sencha User
    Join Date
    Sep 2013
    Posts
    30
    Answers
    1

    Default

    I'm using stateId for the grid and all the columns. The closest thread that would posted to my problem is the second one (http://www.sencha.com/forum/showthread.php?275620) but none of the solutions posted in the thread work for me.

    I would like to emphasize that the issue is not in saving the state, that woks fine, but the issue lies in restoring the state when I refresh the page. In order to show that this is the case I was able to create a controller action onGridpanelBeforeStateSave which prints the state in the state manager when the beforestatesave action is triggered
    Code:
    onGridpanelBeforeStateSave: function(stateful, state, eOpts) {
            console.log("onGridpanelBeforeStateSave: state:");
            console.log(Ext.state.Manager.get("worklistReviewedGrid"));
    }
    When I resize a column, then refresh the page, the page loads and outputs the state from beforestatesave with the column size that was set before I refreshed the page. Although the column size is correct in the manager, the staterestore action is never triggered so the column is reset to its default size.

    To show that the staterestore is not being triggered I added a controller action onGridpanelStateRestore which is triggered on staterestore
    Code:
    onGridpanelStateRestore: function(stateful, state, eOpts) {
            console.log("onGridpanelStateRestore");
    }
    This action is never triggered when I refresh the page.

  5. #4
    Sencha User
    Join Date
    Sep 2013
    Posts
    30
    Answers
    1

    Default

    I created a sample project in Architect that reproduces my issue:

    https://drive.google.com/folderview?...kk&usp=sharing

  6. #5
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,256
    Answers
    759

    Default

    You create the viewport (and as such, the grid) before you create the cookie provider, so there's nothing to restore the state from.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  7. #6
    Sencha User
    Join Date
    Sep 2013
    Posts
    30
    Answers
    1

    Default

    Thanks for the quick response.

    I moved the creation of the CookieProvider to the application constructor instead of the application onLaunch and now the state is being restored as it should be.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •