PDA

View Full Version : need a help about the gridpanel`s store refresh



matjumbo
22 Nov 2010, 7:46 PM
i did a gridpanel,want to keep the scrollbar`s state when the gridpanel refresh.
i can get the scrollbar`s top,left when the store beforeload use 'getScroll() ',and save it to store like 'store.scrollsObj'
then i did code in the event 'load',


var showPanle = tab.getGridEl().down('.x-grid3').down('.x-grid3-viewport').down('.x-grid3-scroller')
showPanle.scrollTo('top',store.scrollsObj.top+10);
showPanle.scrollTo('left',store.scrollsObj.left+10);

when i break debug it ,i find it can do ,but when the gridpane fresh over the scrollbar also go to left:0,top:0
why?
shoud i take another event?

matjumbo
22 Nov 2010, 10:30 PM
who can help me

Condor
23 Nov 2010, 2:46 AM
So you want:

var state;
grid.getStore().on({
beforeload: function(){
if (grid.rendered) {
state = grid.getView().getScrollState();
}
},
load: function(){
if (state) {
grid.getView().restoreScroll(state);
}
}
});

matjumbo
23 Nov 2010, 6:04 PM
So you want:

var state;
grid.getStore().on({
beforeload: function(){
if (grid.rendered) {
state = grid.getView().getScrollState();
}
},
load: function(){
if (state) {
grid.getView().restoreScroll(state);
}
}
});
thanks! that's right!

shinkenno
12 Feb 2013, 9:42 AM
Hi,

I am trying to achieve the same goal (i.e. keeping the scroll position when the grid is refreshed). The store is automatically refreshed every 5 seconds (by an ajax call) with the function:

RealtimeStore.loadData(realdata);

This function does not fire the beforeload event, so I tried another way by monitoring the bodyscroll event of the grid panel with:

var realtimeGridState;
RealtimeGridPanel.on({
bodyscroll: function(){
if (RealtimeGridPanel.rendered) {
realtimeGridState = RealtimeGridPanel.getView().getScrollState();
console.log('Store ',realtimeGridState);
}
}
});

and reloading the scroll state on the store reloading (as explained in the previous posts):

RealtimeGridPanel.getStore().on({
load: function(){
if (realtimeGridState) {
RealtimeGridPanel.getView().restoreScroll(realtimeGridState);
console.log('Load ',realtimeGridState);
}
}
});

The realtimeGridState is well registered (log are correct), but no matter what, the scroll position is always reset to 0,0 when the grid is refreshed.
Any idea of what is happening?

Thank you!

NB: using ExtJS 3.4.1