From 849c92d431ca2d4d591b2ca61c541aa40f754e83 Mon Sep 17 00:00:00 2001 From: Pekka Hyvönen Date: Thu, 26 Mar 2015 21:23:16 +0200 Subject: Take hidden columns into account with spanned cells #17287 Change-Id: I595c6b7da061ebfa495c7f9f649c935a48190b66 --- client/src/com/vaadin/client/widgets/Grid.java | 45 ++++++++++++++++++-------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'client/src') diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index f9c6ed28fe..73dcccfd1e 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -453,6 +453,8 @@ public class Grid extends ResizeComposite implements } HashSet> columnGroup = new HashSet>(); + // NOTE: this doesn't care about hidden columns, those are + // filtered in calculateColspans() for (Column column : columns) { if (!cells.containsKey(column)) { throw new IllegalArgumentException( @@ -516,39 +518,46 @@ public class Grid extends ResizeComposite implements } void calculateColspans() { - // Reset all cells for (CELLTYPE cell : this.cells.values()) { cell.setColspan(1); } - - List> columnOrder = new ArrayList>( - section.grid.getColumns()); // Set colspan for grouped cells for (Set> group : cellGroups.keySet()) { - if (!checkCellGroupAndOrder(columnOrder, group)) { + if (!checkMergedCellIsContinuous(group)) { + // on error simply break the merged cell cellGroups.get(group).setColspan(1); } else { - int colSpan = group.size(); - cellGroups.get(group).setColspan(colSpan); + int colSpan = 0; + for (Column column : group) { + if (!column.isHidden()) { + colSpan++; + } + } + // colspan can't be 0 + cellGroups.get(group).setColspan(Math.max(1, colSpan)); } } } - private boolean checkCellGroupAndOrder( - List> columnOrder, Set> cellGroup) { - if (!columnOrder.containsAll(cellGroup)) { + private boolean checkMergedCellIsContinuous( + Set> mergedCell) { + // no matter if hidden or not, just check for continuous order + final List> columnOrder = new ArrayList>( + section.grid.getColumns()); + + if (!columnOrder.containsAll(mergedCell)) { return false; } for (int i = 0; i < columnOrder.size(); ++i) { - if (!cellGroup.contains(columnOrder.get(i))) { + if (!mergedCell.contains(columnOrder.get(i))) { continue; } - for (int j = 1; j < cellGroup.size(); ++j) { - if (!cellGroup.contains(columnOrder.get(i + j))) { + for (int j = 1; j < mergedCell.size(); ++j) { + if (!mergedCell.contains(columnOrder.get(i + j))) { return false; } } @@ -791,6 +800,14 @@ public class Grid extends ResizeComposite implements assert grid != null; return grid; } + + protected void updateColSpans() { + for (ROWTYPE row : rows) { + if (row.hasSpannedCells()) { + row.calculateColspans(); + } + } + } } /** @@ -4092,6 +4109,8 @@ public class Grid extends ResizeComposite implements } } grid.columnHider.updateToggleValue(this); + grid.header.updateColSpans(); + grid.footer.updateColSpans(); scheduleColumnWidthRecalculator(); this.grid.fireEvent(new ColumnVisibilityChangeEvent(this, hidden, userOriginated)); -- cgit v1.2.3