}
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() {
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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 "));
+ }
+}