summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xclient/src/main/java/com/vaadin/client/widgets/Grid.java13
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridFrozenColumnReplace.java44
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridFrozenColumnReplaceTest.java34
3 files changed, 89 insertions, 2 deletions
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 6d22dfc5ca..2faddaf68d 100755
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -7398,8 +7398,17 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
private void updateFrozenColumns() {
- escalator.getColumnConfiguration()
- .setFrozenColumnCount(getVisibleFrozenColumnCount());
+ int visibleFrozenColumnCount = getVisibleFrozenColumnCount();
+ ColumnConfiguration columnConfiguration = escalator
+ .getColumnConfiguration();
+ if (columnConfiguration.getColumnCount() < visibleFrozenColumnCount) {
+ // new columns may not have got added yet, delay and check the
+ // correct count again
+ Scheduler.get().scheduleFinally(() -> columnConfiguration
+ .setFrozenColumnCount(getVisibleFrozenColumnCount()));
+ } else {
+ columnConfiguration.setFrozenColumnCount(visibleFrozenColumnCount);
+ }
}
private int getVisibleFrozenColumnCount() {
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridFrozenColumnReplace.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridFrozenColumnReplace.java
new file mode 100644
index 0000000000..7ddb35784a
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridFrozenColumnReplace.java
@@ -0,0 +1,44 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.SelectionMode;
+
+public class GridFrozenColumnReplace extends SimpleGridUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<String> grid = new Grid<>();
+ grid.addColumn(String::toString).setId("id1").setCaption("Frozen 1");
+ grid.addColumn(String::toString).setId("id2").setCaption("Col 2");
+ grid.setSelectionMode(SelectionMode.MULTI);
+ grid.setFrozenColumnCount(1);
+
+ Button button = new Button("Replace columns");
+ button.addClickListener(e -> {
+ grid.removeAllColumns(); // will change frozenColumnCount to 0
+
+ grid.addColumn(String::toString).setId("id1")
+ .setCaption("New Frozen 1");
+ grid.addColumn(String::toString).setId("id2")
+ .setCaption("New Frozen 2");
+ grid.addColumn(String::toString).setId("id3")
+ .setCaption("New Col 3");
+ grid.setFrozenColumnCount(2);
+ });
+
+ addComponents(grid, button);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "It should be possible to remove and replace columns on same round trip "
+ + "even if some of them are frozen.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11824;
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridFrozenColumnReplaceTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridFrozenColumnReplaceTest.java
new file mode 100644
index 0000000000..4ad8a48fa2
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridFrozenColumnReplaceTest.java
@@ -0,0 +1,34 @@
+package com.vaadin.tests.components.grid;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class GridFrozenColumnReplaceTest extends SingleBrowserTest {
+
+ @Test
+ public void testChangingColumns() {
+ openTestURL("debug");
+
+ GridElement grid = $(GridElement.class).first();
+ String caption = grid.getHeaderCell(0, 1).getText();
+ assertFalse("Unexpected column caption: " + caption,
+ caption != null && caption.startsWith("New "));
+
+ $(ButtonElement.class).first().click();
+
+ assertEquals("Unexpected error notifications,", 0,
+ findElements(By.className("v-Notification-error")).size());
+
+ caption = grid.getHeaderCell(0, 1).getText();
+ assertTrue("Unexpected column caption: " + caption,
+ caption != null && caption.startsWith("New "));
+ }
+}