Skip to content

Commit b6ece49

Browse files
authored
Fix compatibility Grid column reorder with partially hidden joined cells (#12385)
Fixes #12377
1 parent 5144101 commit b6ece49

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

compatibility-client/src/main/java/com/vaadin/v7/client/widgets/Grid.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,11 +4629,14 @@ private void calculatePossibleDropPositions() {
46294629
}
46304630
final boolean isDraggedCellRow = row.equals(draggedCellRow);
46314631
for (int cellColumnIndex = frozenColumns; cellColumnIndex < getColumnCount(); cellColumnIndex++) {
4632-
StaticCell cell = row.getCell(getColumn(cellColumnIndex));
4633-
int colspan = cell.getColspan();
4634-
if (colspan <= 1) {
4632+
// some of the columns might be hidden, use cell groups
4633+
// rather than cell spans to determine actual span
4634+
Set<Column<?, ?>> cellGroup = row
4635+
.getCellGroupForColumn(getColumn(cellColumnIndex));
4636+
if (cellGroup == null) {
46354637
continue;
46364638
}
4639+
int colspan = cellGroup.size();
46374640
final int cellColumnRightIndex = cellColumnIndex + colspan;
46384641
final Range cellRange = Range.between(cellColumnIndex,
46394642
cellColumnRightIndex);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.vaadin.v7.tests.components.grid;
2+
3+
import com.vaadin.server.VaadinRequest;
4+
import com.vaadin.tests.components.AbstractTestUI;
5+
import com.vaadin.v7.ui.Grid;
6+
import com.vaadin.v7.ui.Grid.Column;
7+
import com.vaadin.v7.ui.Grid.HeaderRow;
8+
9+
@SuppressWarnings("deprecation")
10+
public class GridReorderMerged extends AbstractTestUI {
11+
12+
@SuppressWarnings("unchecked")
13+
@Override
14+
protected void setup(VaadinRequest request) {
15+
Grid grid = new Grid();
16+
HeaderRow headerRow = grid.prependHeaderRow();
17+
for (int i = 1; i < 10; ++i) {
18+
String propertyId = "" + i;
19+
Column column = grid.addColumn(propertyId);
20+
column.setHidable(true);
21+
if (i == 5) {
22+
column.setHidden(true);
23+
}
24+
// add one value per row for easier visualization
25+
grid.getContainerDataSource().addItem(i).getItemProperty(propertyId)
26+
.setValue(propertyId);
27+
}
28+
headerRow.join("1", "2", "3").setText("1");
29+
headerRow.join("4", "5", "6").setText("2"); // middle column hidden
30+
headerRow.join("7", "8", "9").setText("3");
31+
grid.setColumnReorderingAllowed(true);
32+
addComponent(grid);
33+
}
34+
35+
@Override
36+
protected Integer getTicketNumber() {
37+
return 12377;
38+
}
39+
40+
@Override
41+
protected String getTestDescription() {
42+
return "Reordering columns should respect joined cells "
43+
+ "even when some columns are hidden.";
44+
}
45+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.vaadin.v7.tests.components.grid;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
import org.openqa.selenium.interactions.Actions;
7+
8+
import com.vaadin.testbench.elements.GridElement;
9+
import com.vaadin.testbench.elements.GridElement.GridCellElement;
10+
import com.vaadin.tests.tb3.MultiBrowserTest;
11+
12+
public class GridReorderMergedTest extends MultiBrowserTest {
13+
14+
@Test
15+
public void dragMerged() {
16+
openTestURL();
17+
GridElement grid = $(GridElement.class).first();
18+
GridCellElement headerCell0_0 = grid.getHeaderCell(0, 0);
19+
GridCellElement headerCell0_4 = grid.getHeaderCell(0, 4);
20+
new Actions(driver).dragAndDrop(headerCell0_0, headerCell0_4).perform();
21+
22+
// ensure the first merged block got dragged over the entire second
23+
// merged block
24+
assertEquals("Unexpected column order,", "6",
25+
grid.getHeaderCell(1, 1).getText());
26+
}
27+
}

0 commit comments

Comments
 (0)