From cc39c3db5895fb950814b97d6db5c1712fd8e078 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 14 Jan 2013 20:38:01 +0200 Subject: Maintain Table scroll position when changing expand (#10489, #10106) Change-Id: I4937d8943eab65cd4da2ec2e01af5935f96e244d --- client/src/com/vaadin/client/ui/VScrollTable.java | 14 ++++++++++++++ .../ui/orderedlayout/VAbstractOrderedLayout.java | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 021ab8fac1..9ac9532ae4 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -267,6 +267,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets, */ private double lastKnownRowHeight = Double.NaN; + /** + * Remember scroll position when getting detached to properly scroll back to + * the location that there is data for if getting attached again. + */ + private int detachedScrollPosition = 0; + /** * Represents a select range of rows */ @@ -1732,6 +1738,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, @Override protected void onDetach() { + detachedScrollPosition = scrollBodyPanel.getScrollPosition(); rowRequestHandler.cancel(); super.onDetach(); // ensure that scrollPosElement will be detached @@ -1743,6 +1750,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } } + @Override + public void onAttach() { + super.onAttach(); + scrollBodyPanel.setScrollPosition(detachedScrollPosition); + } + /** * Run only once when component is attached and received its initial * content. This function: @@ -7149,4 +7162,5 @@ public class VScrollTable extends FlowPanel implements HasWidgets, public Widget getWidgetForPaintable() { return this; } + } diff --git a/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java b/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java index 84f946dec4..c9f5b92c90 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java @@ -346,11 +346,22 @@ public class VAbstractOrderedLayout extends FlowPanel { if (expandWrapper == null) { expandWrapper = DOM.createDiv(); expandWrapper.setClassName("v-expand"); + + // Detach all widgets before modifying DOM + for (Widget widget : getChildren()) { + orphan(widget); + } + while (getElement().getChildCount() > 0) { Node el = getElement().getChild(0); expandWrapper.appendChild(el); } getElement().appendChild(expandWrapper); + + // Attach all widgets again + for (Widget widget : getChildren()) { + adopt(widget); + } } // Sum up expand ratios to get the denominator @@ -395,6 +406,11 @@ public class VAbstractOrderedLayout extends FlowPanel { */ public void clearExpand() { if (expandWrapper != null) { + // Detach all widgets before modifying DOM + for (Widget widget : getChildren()) { + orphan(widget); + } + lastExpandSize = -1; while (expandWrapper.getChildCount() > 0) { Element el = expandWrapper.getChild(0).cast(); @@ -409,6 +425,11 @@ public class VAbstractOrderedLayout extends FlowPanel { } expandWrapper.removeFromParent(); expandWrapper = null; + + // Attach children again + for (Widget widget : getChildren()) { + adopt(widget); + } } } -- cgit v1.2.3