1. #1
    Sencha User MtAiryEd's Avatar
    Join Date
    Dec 2007
    Posts
    93
    Vote Rating
    0
    MtAiryEd is on a distinguished road

      0  

    Default How to retain scroll position after store load

    How to retain scroll position after store load


    I need to have a grid scroll to the position it was in prior to a load. Currently, upon load, it resets back to the top.

    I've searched here and only found how to scroll to the top or bottom of a grid.

    Any help would be appreciated.

  2. #2
    Ext User
    Join Date
    Aug 2007
    Posts
    84
    Vote Rating
    0
    ohhowihateie is on a distinguished road

      0  

    Default


    Maybe you could try using an Ext.state.CookieProvider to save the location for each scroll and then scroll to it after the load.

    Are you trying to append the data, or replace the data? If you are trying to replace the data it seems odd that you would want to save the scroll position because the past scroll position may or may not be in the store upon reload.

  3. #3
    Sencha User MtAiryEd's Avatar
    Join Date
    Dec 2007
    Posts
    93
    Vote Rating
    0
    MtAiryEd is on a distinguished road

      0  

    Default


    I am replacing the data, but...

    My data doesn't change much. There is one column that displays a status duration. The status duration changes every time. For example, if the refresh period is 30 seconds on the page, the status duration will either increase by 30 seconds, or perhaps a status will change and will go to zero. If a user is looking at row 89 of a grid that has 112 rows, and the grid refreshes and takes the user back to row one, the user has to go find row 89 again, upon each refresh. Kind of a poor GUI principle.

  4. #4
    Sencha User MtAiryEd's Avatar
    Join Date
    Dec 2007
    Posts
    93
    Vote Rating
    0
    MtAiryEd is on a distinguished road

      0  

    Default


    Maybe you could try using an Ext.state.CookieProvider to save the location for each scroll and then scroll to it after the load.
    Oh, and how would I go about getting my scroll location?

    Thanks!

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Include this in your viewConfig:

    Code:
                onLoad: Ext.emptyFn,
                listeners: {
                    beforerefresh: function(v) {
                        v.scrollTop = v.scroller.dom.scrollTop;
                    },
                    refresh: function(v) {
                        v.scroller.dom.scrollTop = v.scrollTop;
                    },
                }

  6. #6
    Sencha User MtAiryEd's Avatar
    Join Date
    Dec 2007
    Posts
    93
    Vote Rating
    0
    MtAiryEd is on a distinguished road

      0  

    Default


    That worked!

    Thanks Animal!!

  7. #7
    Sencha User MtAiryEd's Avatar
    Join Date
    Dec 2007
    Posts
    93
    Vote Rating
    0
    MtAiryEd is on a distinguished road

      0  

    Default


    May I suggest that this be entered into the Grid FAQ?

  8. #8
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Done.

  9. #9
    Sencha User MtAiryEd's Avatar
    Join Date
    Dec 2007
    Posts
    93
    Vote Rating
    0
    MtAiryEd is on a distinguished road

      0  

    Default


    Code:
              onLoad: Ext.emptyFn,
                listeners: {
                    beforerefresh: function(v) {
                        v.scrollTop = v.scroller.dom.scrollTop;
                    },
                    refresh: function(v) {
                        v.scroller.dom.scrollTop = v.scrollTop;
                    },
                }
    Has anyone seen this stop working in V2.2? I am losing my scroll position after a refresh. In debugging, the scroll is lost AFTER the scroll position is set by this line: "v.scroller.dom.scrollTop = v.scrollTop;".

    It appears to be happening in ext-all-debug.js at line #10860
    Code:
    this.fireEvent("load", this, r, options);
    Thanks,
    Ed

  10. #10
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    89
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Haven't checked, but I assume you need to set deferRowRender:false in the viewConfig.