Search code examples
extjs3

How do you stop scrolling to top when grid store is reloaded


I have an app that uses ExtJS 3.3.0. It uses an EditorGridPanel in which after the store is reloaded - I would like it to preserve the scroll position of the grid rather than sending it back up to the top.

Because this is an earlier version of ExtJS - this DOES NOT work:

viewConfig: {
   preserveScrollOnRefresh: true
}

So far the only thing I can come up with is to save the position of the scroll bar prior to loading - and then reset the position once the reload is complete.

I can get as far as saving the position:

var scrollPos;

bodyscroll: function(sl, st) {
    scrollPos = st;
},

However I can't figure out how to set the position afterwards.

Any suggestions?

Thanks in advance.


Solution

  • There might be multiple ways to do this but one way is to use the scroller element, which is accessible through the grid's gridview. See fiddle here: Grid scoll save/restore.

    To get scroll value (which you've already got figured out):

    var top = grid.getView().scroller.getScroll().top;
    

    To restore:

    grid.getView().scroller.scrollTo('top',top);