diff options
5 files changed, 41 insertions, 2 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 149ef4c1f9..bfc605ee2e 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 @@ -73,7 +73,12 @@ public class ColumnConnector extends AbstractExtensionConnector { return null; } }; + + // Initially set a renderer + updateRenderer(); + getParent().addColumn(column, getState().internalId); + } @SuppressWarnings("unchecked") @@ -149,6 +154,7 @@ public class ColumnConnector extends AbstractExtensionConnector { // time to remove columns (and have problems with frozen columns) // before throwing everything away parent.removeColumn(column); + parent = null; } column = null; } diff --git a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java index 566c7c732f..ae3c6f4cc1 100644 --- a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java +++ b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java @@ -366,6 +366,9 @@ public class DataCommunicator<T> extends AbstractExtension { public void addDataGenerator(DataGenerator<T> generator) { Objects.requireNonNull(generator, "generator cannot be null"); generators.add(generator); + + // Make sure data gets generated when adding data generators. + reset(); } /** diff --git a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java index dcf27fb357..947be8f522 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java @@ -158,6 +158,7 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>> iterator.remove(); } } + cell.detach(); } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddColumn.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddColumn.java index e771b9cc78..8846091512 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddColumn.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddColumn.java @@ -1,18 +1,34 @@ package com.vaadin.tests.components.grid; +import com.vaadin.annotations.Widgetset; import com.vaadin.data.ValueProvider; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; import com.vaadin.ui.renderers.NumberRenderer; +@Widgetset("com.vaadin.DefaultWidgetSet") public class GridAddColumn extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { Grid<String> grid = new Grid<>(); + createColumns(grid); + grid.setItems("a", "aa", "aaa"); + addComponent(grid); + + addComponent(new Button("Replace columns", e -> { + grid.removeAllColumns(); + createColumns(grid); + Notification.show("Columns replaced."); + })); + } + + private void createColumns(Grid<String> grid) { Column<String, String> col0 = grid.addColumn(ValueProvider.identity()) .setCaption("First column"); grid.getDefaultHeaderRow().getCell(col0) @@ -21,7 +37,5 @@ public class GridAddColumn extends AbstractTestUI { grid.addColumn(String::length); grid.addColumn(string -> -string.length()); grid.addColumn(string -> new Object()); - grid.setItems("a", "aa", "aaa"); - addComponent(grid); } } diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddColumnTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddColumnTest.java index ca5ad8ec50..e3595e7674 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddColumnTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddColumnTest.java @@ -5,8 +5,10 @@ import org.junit.Before; import org.junit.Test; import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.tests.tb3.SingleBrowserTest; public class GridAddColumnTest extends SingleBrowserTest { @@ -64,6 +66,19 @@ public class GridAddColumnTest extends SingleBrowserTest { firstHeader.getText()); } + @Test + public void replace_all_columns() { + $(ButtonElement.class).first().click(); + + // Verify button got clicked + Assert.assertTrue(isElementPresent(NotificationElement.class)); + Assert.assertEquals("Columns replaced.", + $(NotificationElement.class).first().getText()); + + // Run default rendering test + columns_rendered_correctly(); + } + private void assertCellEquals(int rowIndex, int colIndex, String content) { Assert.assertEquals("Cell text should equal", content, grid.getCell(rowIndex, colIndex).getText()); |