View Full Version : How to reset Ext.Panel scrollbar ?

4 Apr 2011, 2:41 PM
I have an Ext.Panel to which I've added a bunch of components. The autoscroll scrollbar works fine, except that it doesn't reset to the top when the activate event is fired, or when the components/content of the panel changes, or ever. I need some mechanism to reset the scrollbar to the top of the panel.

The Ext.Panel doesn't have a "view" property, the way Ext.grid.GridPanel does, so I can't use myPanel.view.scroller.dom.scrollTop the way I do with GridPanel elsewhere in my application.

Searched the forums for help on thisbut couldn't find anything that helped.


4 Apr 2011, 4:37 PM
The scroller is just an Element under the GridPanel. Have you tried that on the Panel's body element?

5 Apr 2011, 6:37 AM
Not sure what you're suggesting. I tried the following:

activate: function(p) {
p.body.scroller.dom.scrollTop = 0;
}'p' is the Ext.Panel object. Got a runtime error: "Error: 'body.scroller.dom' is null or not an object".

5 Apr 2011, 7:43 AM


Not testing code, just suggesting at this point.

5 Apr 2011, 7:47 AM
Or better yet, since I have looked at the API docs...

p.body.scrollTo("top", 0, true);

5 Apr 2011, 10:14 AM
This worked! Thanks so much Mitchell. Somehow it didn't occur to me that Element might have what I wanted.

Another question. I found out that setActiveItem() only fires the 'activate' event if the item wasn't already active, so i needed to explicitly call fireEvent("activate",...) when I change the contents of the panel. Isn't there some event that should be firing already when contents of the panel are getting changed dramatically (i'm using panel.removeAll() and panel.add())? What event is it? I tried using bodyCfg to add a listener to the body for its DOMSubtreeModified event, but that event never got fired. I tried Panel's "render" event but that gave an error when i tried to access component.body.scrollTo.. Also tried Panel's "removed" event, which is supposed to fire "when a component is removed from an Ext.Container" but somehow that wasn't getting fired.. What events should be getting fired when i'm doing panel.removeAll() and panel.add()? I'm curious.