]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ensure #cell[N] always scrolls row N into view (#20423)
authorArtur Signell <artur@vaadin.com>
Tue, 25 Oct 2016 15:27:20 +0000 (18:27 +0300)
committerPekka Hyvönen <pekka@vaadin.com>
Fri, 9 Dec 2016 07:39:00 +0000 (09:39 +0200)
Change-Id: I99347ee1d0f2f13fcb8e110d2e7192590e4f9456

client/src/main/java/com/vaadin/client/widgets/Escalator.java
uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridScrollTest.java

index 3d2c80ddbead567a9ea3f8cded13812a7cc6828c..e3e0dfa0e42dff55c168d73b5b4e404d6cb17b72 100644 (file)
@@ -6616,15 +6616,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")) {
index 1c6ae8b44ee6b12b448f8bc63cba7282b3e7c8e4..49b44a01a77d026689141f4ad32ee19b7847dae4 100644 (file)
@@ -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());
+    }
 }