I’m using SmartGWT 5.1-p20170201 on Firefox 26.0 on Windows
In my application I do the following:
This results in the scroll position being moved from the bottom to the top.
My desired behavior is that after I remove and replace a member the scroll position is preserved.
How can I do this?
Is there a way to disable this automatic scrolling to the top?
Is there a way to save and restore the scroll position?
Here is the sample code which demonstrates this behavior:
To show the behavior do the following:
In my application I do the following:
- Inside of a scrolling layout (setOverflow(Overflow.AUTO)) I add content by adding a layout and then adding members to that layout
- I scroll to the bottom of the scrolling layout
- Through user interaction I replace the member added above with a new member that is constructed in the same way.
This results in the scroll position being moved from the bottom to the top.
My desired behavior is that after I remove and replace a member the scroll position is preserved.
How can I do this?
Is there a way to disable this automatic scrolling to the top?
Is there a way to save and restore the scroll position?
Here is the sample code which demonstrates this behavior:
Code:
[B]public[/B] [B]class[/B] ScrollPositionEntry [B]extends[/B] VLayout [B]implements[/B] EntryPoint {
[B]private[/B] VLayout scrollingLayout;
[B]private[/B] VLayout container;
@Override
[B]public[/B] [B]void[/B] onModuleLoad() {
setDefaultLayoutAlign(Alignment.[B][I]CENTER[/I][/B]);
scrollingLayout = scrollingLayout();
addMember(scrollingLayout);
container = container();
scrollingLayout.addMember(container);
addContentToContainer();
addMember([B]new[/B] Button() {
{
setTitle("Replace");
addClickHandler(event -> {
Canvas toReplace = scrollingLayout.getMember(0);
toReplace.destroy();
container = container();
scrollingLayout.addMember(container, 0);
addContentToContainer();
});
}
});
show();
}
[B]private[/B] VLayout container() {
[B]return[/B] [B]new[/B] VLayout() {
{
setWidth(300);
setAutoHeight();
setBorder("6px solid red");
}
};
}
[B]private[/B] [B]void[/B] addContentToContainer() {
Stream.[I]of[/I]("red", "green", "orange", "yellow", "purple")
.forEach(color -> container.addMember([B]new[/B] HLayout() {
{
setBorder("6px solid " + color);
setWidth100();
setHeight(100);
}
}));
}
[B]private[/B] VLayout scrollingLayout() {
[B]return[/B] [B]new[/B] VLayout() {
{
setBorder("6px solid blue");
setDefaultLayoutAlign(Alignment.[B][I]CENTER[/I][/B]);
setHeight(400);
setMargin(10);
setMembersMargin(10);
setOverflow(Overflow.[B][I]AUTO[/I][/B]);
setVisible([B]true[/B]);
setWidth(400);
}
};
}
}
- Run the application
- Scroll to the bottom of the scrolling layout
- Click the “Replace” button
- This will result in the scroll position to be set at the top
Comment