-
29 Sep 2007 2:31 AM #1
Is there any way to keep scroll position of Grid on load
Is there any way to keep scroll position of Grid on load
I've read the previous thread "Grid Loses Selection and Scroll Position On Data Store Load" and tried the way to restore scroll position after ds.load. It works, but "However there is still a visible twitch in the grid as it scrolls to the top and then back to the restored position.", I also tried :
I think the option to turn off redraw grid while only update data in it is very important requirement. The typical usage such as real time stock quotes display has to have this option, or it can't work well, obviously. So can Ext team put some effort on it?Code:grid = new Ext.grid.Grid('guests', { ds: ds, cm: colModel, view: new Ext.grid.GridView({ focusRow: Ext.emptyFn, ensureVisible: Ext.emptyFn }) });
-
4 Oct 2007 10:26 AM #2
It's a bit of a hack, but if you create your grid as shown below, the grid scroll position will stay where it is when the data store is reloaded. The selection remains the same as well. The onLoad() function of the grid calls scrollToTop(). By eliminating scrollToTop(), the grid no longer moves when it is reloaded. The only drawback is that you can no longer call scrollToTop() on the grid.
Code:new Ext.grid.Grid('parent', { ... view: new Ext.grid.GridView({ scrollToTop: Ext.emptyFn }) });
-
7 Oct 2007 7:37 PM #3
scrollToTop: Ext.emptyFn works!
scrollToTop: Ext.emptyFn works!
Thank you, wck555, It just works as you said. Though I have to forget scrollToTop, but I got a grid without blinking
-
7 Oct 2007 9:32 PM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Forest Grove, OR
- Posts
- 1,038
- Vote Rating
- 0
An alternative would be user Ext.override() to add a new method to the gridView that implements a copy of the scrollToTop() method. Then, override the built-in scrollToTop() method pointing it at the emptyFn() function, as mentioned above.
Now, if you need to actually scroll to the top, you call your own scrollTop() method.Code:Ext.override(Ext.grid.GridView, { scrollTop : function() { this.scroller.dom.scrollTop = 0; this.scroller.dom.scrollLeft = 0; }, scrollToTop : Ext.emptyFn });
Yet another alternative is to use the override mentioned in the post above, and then simply access the gridView's scroller and call it's built-in scrollTo() method. Assuming "grid" is a variable holding a reference to your grid, you can do:
Additionally, this approach means you can animate the scroll, if you choose:Code:grid.getView().scroller.scrollTo('top', 0);
or get fancy with it:Code:grid.getView().scroller.scrollTo('top', 0, true);
Code:grid.getView().scroller.scrollTo('top', 0, { easing: 'bounceOut' });Jeff Howden
Ext JS - Support Team Volunteer
jeff@extjs.com
Any and all code samples that are authored by me and posted on the Ext forums or website are hereby released into the public domain and I release anyone or entity of liability by using said code samples unless explicitly stated otherwise.
Opinions are mine and not necessarily endorsed by Ext, LLC. Please do not contact me directly for assistance unless requested by me.
-
18 Jan 2008 12:45 AM #5
-
20 Jul 2009 4:49 PM #6
I realize this thread is old, but I found my answer here and thought I'd add my solution for the next person that hits it...
I came up with a less destructive version that I am using with 3.0:
This way you don't have to remove the scrollToTop function and you can choose to override the scrollToTop behavior only at specific loads with something like:Code:Ext.override(Ext.grid.GridView, { holdPosition: false, onLoad : function(){ if (!this.holdPosition) this.scrollToTop(); this.holdPosition = false } });
I needed this feature because I still want it to scroll to the top properly when I load with new parameters.Code:grid.getView().holdPosition = true grid.getStore().reload()
-
23 Sep 2009 10:36 AM #7
-
18 Mar 2010 10:43 PM #8
-
3 Aug 2011 3:43 PM #9
thanks..
thanks..
Thanks Chris_S. Neat override solution.

-
4 Aug 2011 10:56 PM #10
Stop Scrolling From Top
Stop Scrolling From Top
Can anybody send me the complete code of this problem.


Reply With Quote


