]> source.dussan.org Git - vaadin-framework.git/commitdiff
Only sort when enter is pressed on default header (#16732)
authorArtur Signell <artur@vaadin.com>
Mon, 18 May 2015 20:40:25 +0000 (23:40 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 25 May 2015 20:44:58 +0000 (20:44 +0000)
Change-Id: I3bae7c341064f26c6be3c9b66b33239716043fec

client/src/com/vaadin/client/widgets/Grid.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java

index 07074eeddf8ec80b8d0af5c1c49a9211ef6d13b8..53e0566e8d8f354e42a588553e62dbf5999ed7e6 100644 (file)
@@ -5056,9 +5056,12 @@ public class Grid<T> extends ResizeComposite implements
                 if (event.getNativeKeyCode() != KeyCodes.KEY_ENTER) {
                     return;
                 }
-
-                sorter.sort(event.getFocusedCell().getColumn(),
-                        event.isShiftKeyDown());
+                if (getHeader().getRow(event.getFocusedCell().getRowIndex())
+                        .isDefault()) {
+                    // Only sort for enter on the default header
+                    sorter.sort(event.getFocusedCell().getColumn(),
+                            event.isShiftKeyDown());
+                }
             }
         });
 
index b06644f0c895f42de280e2be3136839b765e2daa..cff8ade054c8551d179e4cb5a7828d0404d3e9f4 100644 (file)
@@ -212,6 +212,33 @@ public class GridSortingTest extends GridBasicFeaturesTest {
         new Actions(getDriver()).keyUp(key).perform();
     }
 
+    @Test
+    public void testKeyboardSortingMultipleHeaders() {
+        openTestURL();
+        selectMenuPath("Component", "Header", "Append row");
+
+        // Sort according to first column by clicking
+        getGridElement().getHeaderCell(0, 0).click();
+        assertColumnIsSorted(0);
+
+        // Try to sort according to second column by pressing enter on the new
+        // header
+        sendKey(Keys.ARROW_RIGHT);
+        sendKey(Keys.ARROW_DOWN);
+        sendKey(Keys.ENTER);
+
+        // Should not have sorted
+        assertColumnIsSorted(0);
+
+        // Sort using default header
+        sendKey(Keys.ARROW_UP);
+        sendKey(Keys.ENTER);
+
+        // Should have sorted
+        assertColumnIsSorted(1);
+
+    }
+
     @Test
     public void testKeyboardSorting() {
         openTestURL();