From 5143e779a6febd719389716ccaf7e69741710925 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 18 Jul 2017 13:11:28 +0300 Subject: Fix Grid header merging on init (#9688) Fixes #9686 --- .../com/vaadin/client/connectors/grid/ColumnConnector.java | 6 ++++++ client/src/main/java/com/vaadin/client/widgets/Grid.java | 2 +- .../java/com/vaadin/tests/components/grid/GridComponents.java | 10 +++++++--- .../com/vaadin/tests/components/grid/GridComponentsTest.java | 9 +++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java index c47488f78e..7ac6c518ad 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java @@ -20,6 +20,7 @@ import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.connectors.AbstractRendererConnector; import com.vaadin.client.extensions.AbstractExtensionConnector; import com.vaadin.client.widgets.Grid.Column; +import com.vaadin.client.widgets.Grid.HeaderCell; import com.vaadin.shared.data.DataCommunicatorConstants; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.grid.ColumnState; @@ -48,6 +49,11 @@ public class ColumnConnector extends AbstractExtensionConnector { public String getConnectorId() { return connectorId; } + + @Override + protected void setDefaultHeaderContent(HeaderCell cell) { + // NO-OP, Server takes care of header contents. + } } private CustomColumn column; diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index 45937e0c07..9a5674e86e 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -4853,7 +4853,7 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, private void updateHeader() { HeaderRow row = grid.getHeader().getDefaultRow(); if (row != null) { - row.getCell(this).setText(headerCaption); + setDefaultHeaderContent(row.getCell(this)); if (isHidable()) { grid.columnHider.updateHidingToggle(this); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java index dce85d3be9..a48c8400c1 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java @@ -25,7 +25,8 @@ public class GridComponents extends AbstractTestUIWithLog { @Override protected void setup(VaadinRequest request) { Grid grid = new Grid<>(); - grid.addColumn(string -> new Label(string), new ComponentRenderer()); + grid.addColumn(string -> new Label(string), new ComponentRenderer()) + .setCaption("Label"); grid.addComponentColumn(string -> { if (textFields.containsKey(string)) { log("Reusing old text field for: " + string); @@ -41,7 +42,7 @@ public class GridComponents extends AbstractTestUIWithLog { textFields.put(string, textField); }); return textField; - }); + }).setId("textField").setCaption("TextField"); grid.addColumn(string -> { Button button = new Button("Click Me!", e -> Notification.show( @@ -49,10 +50,13 @@ public class GridComponents extends AbstractTestUIWithLog { Type.WARNING_MESSAGE)); button.setId(string.replace(' ', '_').toLowerCase()); return button; - }, new ComponentRenderer()); + }, new ComponentRenderer()).setId("button").setCaption("Button"); // make sure the buttons and focus outlines fit completely in a row grid.setRowHeight(40); + grid.getDefaultHeaderRow().join("textField", "button") + .setText("Other Components"); + addComponent(grid); grid.setSizeFull(); diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java index b74386e2d9..af985aad9a 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridComponentsTest.java @@ -82,6 +82,15 @@ public class GridComponentsTest extends MultiBrowserTest { assertRowExists(999, "Row 999"); } + @Test + public void testHeaders() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + Assert.assertEquals("Label", grid.getHeaderCell(0, 0).getText()); + Assert.assertEquals("Other Components", + grid.getHeaderCell(0, 1).getText()); + } + private void assertRowExists(int i, String string) { GridRowElement row = $(GridElement.class).first().getRow(i); Assert.assertEquals("Label text did not match", string, -- cgit v1.2.3