diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-08-01 12:20:21 +0000 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-08-01 12:20:21 +0000 |
commit | 85c03155dc02e61dd10a9c861b064204bdeaca9f (patch) | |
tree | 9a0c38ddcbfb921ccbfc6680fc368aa082514bfd /src/com | |
parent | e1941afd8f00b85da9c87a863828b54c755db684 (diff) | |
download | vaadin-framework-85c03155dc02e61dd10a9c861b064204bdeaca9f.tar.gz vaadin-framework-85c03155dc02e61dd10a9c861b064204bdeaca9f.zip |
Remember previous row height to maintain table size when all rows are removed (#9132)
svn changeset:24041/svn branch:6.8
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index fa7621e512..c1f90b0157 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -217,6 +217,19 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, private Set<String> noncollapsibleColumns; /** + * The last known row height used to preserve the height of a table with + * custom row heights and a fixed page length after removing the last row + * from the table. + * + * A new VScrollTableBody instance is created every time the number of rows + * changes causing {@link VScrollTableBody#rowHeight} to be discarded and + * the height recalculated by {@link VScrollTableBody#getRowHeight(boolean)} + * to avoid some rounding problems, e.g. round(2 * 19.8) / 2 = 20 but + * round(3 * 19.8) / 3 = 19.66. + */ + private double lastKnownRowHeight = Double.NaN; + + /** * Represents a select range of rows */ private class SelectionRange { @@ -4455,13 +4468,27 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, if (tBodyMeasurementsDone && !forceUpdate) { return rowHeight; } else { - if (tBodyElement.getRows().getLength() > 0) { int tableHeight = getTableHeight(); int rowCount = tBodyElement.getRows().getLength(); rowHeight = tableHeight / (double) rowCount; } else { - if (isAttached()) { + // Special cases if we can't just measure the current rows + if (!Double.isNaN(lastKnownRowHeight)) { + // Use previous value if available + if (BrowserInfo.get().isIE()) { + /* + * IE needs to reflow the table element at this + * point to work correctly (e.g. + * com.vaadin.tests.components.table. + * ContainerSizeChange) - the other code paths + * already trigger reflows, but here it must be done + * explicitly. + */ + getTableHeight(); + } + rowHeight = lastKnownRowHeight; + } else if (isAttached()) { // measure row height by adding a dummy row VScrollTableRow scrollTableRow = new VScrollTableRow(); tBodyElement.appendChild(scrollTableRow.getElement()); @@ -4472,6 +4499,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, return DEFAULT_ROW_HEIGHT; } } + lastKnownRowHeight = rowHeight; tBodyMeasurementsDone = true; return rowHeight; } |