Search code examples
extjsscrollgridreloadstore

ExtJS: Reload datastore without redrawing grid


(ExtJS 3.3.1)

How can I save the scroll position of a grid after I call grid.store.reload()?


Solution

  • I managed to fix it like this:

    this.store = new Ext.data.Store({
        listeners:{
            'load':function (store, records, options) {
                var restoreScroll = function(scrollState){
                    grid.getView().restoreScroll(scrollState);
                };
                if (grid.view && grid.view.scroller){
                    _.delay(restoreScroll, 10,grid.getView().getScrollState());
                }
            }
        }, ...
    }
    

    As you can see, I use _.delay (of the underscore.js framework). It's just like a setTimeout.

    A more optimized version, not using the the function 'restoreScroll' didn't work out. I think that the view is changed when restoreScroll is called. I had to take 10 miliseconds. 1 was not enough. As stated by others, ext.js uses a lot of defer-calls.