PDA

View Full Version : How do I reset a container's scroll position?



hermann.s
16 May 2014, 3:39 AM
Unfortunately,

my container will remember its scroll position after it gets reloaded.
Is there any way to prevent this or reset the position upon reload?

Thank you.

jsakalos
16 May 2014, 4:53 AM
How come it "remembers" is it sateful? Or you use some custom scrolling code?

Anyway, scrollBy (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.container.Container-method-scrollBy) can be used to make it "forget". ;)

hermann.s
21 May 2014, 5:21 AM
Thanks for the reply.
Unfortunately I've already tried this in the console and it won't work.
Nothing happens.


{ xtype: 'container', itemId: 'workInstruction', border: 1, layout: { type: 'fit' }, minHeight: 70, flex: 1, overflowY: 'scroll' }

jsakalos
21 May 2014, 5:57 AM
I do not have your code to run, also I don't know what exactly have you done in the console so only a hint from the above: 'fit' layout never scrolls, it always takes the available space.

hermann.s
21 May 2014, 5:59 AM
What I did was just enter this in the console to see if the position of the scrollbar would be reset :


Ext.ComponentQuery.query('#workInstruction')[0].scrollBy(0, 0, false);

The container has some text inside. If text is too long or the browser's window size is made smaller, then the scrollbar is enabled.

Upon going to a different view and back to the same again, the scroll retains its position, which is not desired.
I then tried the command in the console but nothing happened.
What do you mean fit layout never scrolls?

jsakalos
21 May 2014, 7:22 AM
workInstruction is a container with layout 'fit' what means:


It can only have one item
The item is resized to occupy the full container size


So no scrolling is possible for scrolling to occur the item must be larger than its container.

hermann.s
22 May 2014, 2:37 AM
Thank you for your time in this,

The container is basically empty until it is shown.
When it is shown it is updated with some text.


Ext.ComponentQuery.query('container#workInstruction'[0].update(processInstance.Work_Instruction.replace(/\r/g, '<br />'));

Now, the text might be enough to not fit in the container, in which case the vertical scrollbar appears.
When I scroll to the bottom of the container, then exit the view and re-enter, the scrollbar remains at the bottom.

So, from what you are saying, I understand that I cannot use scrollBy to reset the vertical scrollbar.