}
if (newSize > oldSize) {
+ if (oldSize == 0 && !isHeaderVisible()) {
+ // Fixes framework/issues/11607
+ // Need to recalculate column widths when the
+ // first row is added to a non-header grid,
+ // otherwise the checkbox will be aligned in a
+ // wrong place.
+ recalculateColumnWidths();
+ }
body.insertRows(oldSize, newSize - oldSize);
cellFocusHandler.rowsAddedToBody(Range
.withLength(oldSize, newSize - oldSize));
--- /dev/null
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.VerticalLayout;
+
+public class CheckboxAlignmentWithNoHeaderGrid extends AbstractTestUI {
+
+ List<String> items = new ArrayList<>();
+ int count = 1;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ VerticalLayout lay = new VerticalLayout();
+
+ Grid<String> grid = new Grid<>();
+ grid.setSelectionMode(Grid.SelectionMode.MULTI);
+ grid.setHeaderVisible(false);
+ grid.addColumn(Object::toString);
+
+ grid.setItems(items);
+
+ lay.addComponent(grid);
+ lay.addComponent(new Button("add", e -> {
+ items.add("ABCDEFG" + count);
+ grid.getDataProvider().refreshAll();
+ count++;
+ }));
+ addComponent(lay);
+
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Rows added to empty grid with multiselect and no header should not break ";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 11607;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.components.grid;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class CheckboxAlignmentWithNoHeaderGridTest extends SingleBrowserTest {
+
+ GridElement grid;
+
+ @Before
+ public void init() {
+ openTestURL();
+ grid = $(GridElement.class).first();
+ }
+
+ @Test
+ public void alignments_are_correct() throws IOException {
+ Assert.assertTrue("This should be an empty grid",
+ grid.getRowCount() == 0);
+
+ for (int i =0; i<5; i++) {
+ $(ButtonElement.class).first().click();
+ }
+ sleep(100);
+
+ Assert.assertTrue("This grid should have 5 rows",
+ grid.getRowCount() == 5);
+ compareScreen("alignment");
+ }
+}