From 22ea8caf78f6690ed4414bd0085af7c5bfc21e46 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 1 Jul 2015 14:27:30 +0300 Subject: Fix Grid details on sort to display them on correct rows (#18224) Due to the nature of Container this is only achieved by removing any existing details and reopening those after the sort is done. Change-Id: Ic42186ed85981d5dad4ff0948aa22f7a0404480d --- client/src/com/vaadin/client/widgets/Grid.java | 6 ++++++ .../com/vaadin/data/RpcDataProviderExtension.java | 8 +++++++ .../components/grid/GridDetailsWidthTest.java | 25 ++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index fef6a01640..56b081f6b3 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -5972,6 +5972,12 @@ public class Grid extends ResizeComposite implements RowContainer body = escalator.getBody(); int oldSize = body.getRowCount(); + // Hide all details. + Set oldDetails = new HashSet(visibleDetails); + for (int i : oldDetails) { + setDetailsVisible(i, false); + } + if (newSize > oldSize) { body.insertRows(oldSize, newSize - oldSize); cellFocusHandler.rowsAddedToBody(Range.withLength(oldSize, diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index 9d18736ba8..d291d509b2 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -927,6 +927,14 @@ public class RpcDataProviderExtension extends AbstractExtension { listener.removeListener(); } + // Wipe clean all details. + HashSet detailItemIds = new HashSet( + detailComponentManager.visibleDetailsComponents + .keySet()); + for (Object itemId : detailItemIds) { + detailComponentManager.destroyDetails(itemId); + } + listeners.clear(); activeRowHandler.activeRange = Range.withLength(0, 0); diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsWidthTest.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsWidthTest.java index 0a6f53820e..2def2d0279 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridDetailsWidthTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsWidthTest.java @@ -23,8 +23,11 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; import com.vaadin.tests.tb3.SingleBrowserTest; +@TestCategory("grid") public class GridDetailsWidthTest extends SingleBrowserTest { @Test @@ -64,4 +67,26 @@ public class GridDetailsWidthTest extends SingleBrowserTest { } } + @Test + public void testDetailsOnSort() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Open a details rows + grid.getCell(0, 0).click(); + + GridCellElement cell = grid.getHeaderCell(0, 0); + cell.click(); + cell.click(); + + cell = grid.getCell(2, 0); + WebElement spacer = findElement(By.className("v-grid-spacer")); + Assert.assertEquals("Grid was not sorted correctly", "Hello 0", + cell.getText()); + Assert.assertEquals("Details row was not in correct location", cell + .getLocation().getY() + cell.getSize().getHeight(), spacer + .getLocation().getY()); + + } + } -- cgit v1.2.3