From e22ca2af047391e62195d2d3f07217ead8d88dd6 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 25 Oct 2016 18:27:20 +0300 Subject: [PATCH] Ensure #cell[N] always scrolls row N into view (#20423) Change-Id: I99347ee1d0f2f13fcb8e110d2e7192590e4f9456 --- .../com/vaadin/client/widgets/Escalator.java | 22 +++++++++++-------- .../basicfeatures/server/GridScrollTest.java | 6 +++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index 8dbbfc437d..9eaa7ddd36 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -6682,15 +6682,19 @@ public class Escalator extends Widget } else if (type.equalsIgnoreCase("cell")) { // If wanted row is not visible, we need to scroll there. Range visibleRowRange = getVisibleRowRange(); - if (indices.length > 0 && !visibleRowRange.contains(indices[0])) { - try { - scrollToRow(indices[0], ScrollDestination.ANY, 0); - } catch (IllegalArgumentException e) { - getLogger().log(Level.SEVERE, e.getMessage()); + if (indices.length > 0) { + // Contains a row number, ensure it is available and visible + boolean rowInCache = visibleRowRange.contains(indices[0]); + + // Scrolling might be a no-op if row is already in the viewport + scrollToRow(indices[0], ScrollDestination.ANY, 0); + + if (!rowInCache) { + // Row was not in cache, scrolling caused lazy loading and + // the caller needs to wait and call this method again to be + // able to get the requested element + return null; } - // Scrolling causes a lazy loading event. No element can - // currently be retrieved. - return null; } container = getBody(); } else if (type.equalsIgnoreCase("footer")) { @@ -6834,4 +6838,4 @@ public class Escalator extends Widget double getMinCellWidth(int colIndex) { return columnConfiguration.getMinCellWidth(colIndex); } -} \ No newline at end of file +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java index fbd36f87f9..815d6f72a6 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java @@ -68,4 +68,10 @@ public class GridScrollTest extends GridBasicFeaturesTest { active); } + @Test + public void scrollIntoViewThroughSubPart() { + openTestURL("theme=valo"); + GridElement grid = $(GridElement.class).first(); + assertEquals("(10, 0)", grid.getCell(10, 0).getText()); + } } -- 2.39.5