EagleFox
EagleFox

Reputation: 1367

How to save scroll position on an extjs form?

I have a long form with comboboxes and buttons that add element to the form. Every time combobox's value gets upldated or elements get added, it scrolls up to the top of the form. I want the scrollbar to retain its position. I tried saving current scroll position by doing

     this.myForm.getScrollPosition();

But I get getScrollPosition is not a function error.

Any help on this?

Upvotes: 1

Views: 7109

Answers (1)

If you are using extjs there is a way to manipulate the scroll using the Ext.dom.Element class, each component in Extjs inherits from it, then if you add a new component that modifies the height or width of your form, you can first get the height and width of that component using:

var newcompwidth = comboboxexample.getWidth();
var newcompheight = comboboxeample.getHeight();

Later you can modify the scroll value using scrollTo method like this:

myformcontainer.getEl().scrollTo('Top',myformcontainer.getEl().getScroll().top - newcompheight);

myformcontainer.getEl().scrollTo('Top',myformcontainer.getEl().getScroll().left - newcompwidth);

there are other methods like scrollBy or scroll but I didn't test it yet, I guess this will help you.

the docs: http://docs.sencha.com/extjs/4.1.0/#!/api/Ext.dom.Element

Upvotes: 4

Related Questions