From a4e2d461d5781b6b69ebda0757cc1c7e3d871f1d Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 15 May 2018 15:10:59 +0300 Subject: Fix Grid clearSortOrder not updating state (#10917) Fixes #9074 --- server/src/main/java/com/vaadin/ui/Grid.java | 11 +---------- .../java/com/vaadin/tests/server/component/grid/GridTest.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index aedd32035c..3bf65c6c9b 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -4111,8 +4111,7 @@ public class Grid extends AbstractListing implements HasComponents, * Clear the current sort order, and re-sort the grid. */ public void clearSortOrder() { - sortOrder.clear(); - sort(false); + setSortOrder(Collections.emptyList()); } /** @@ -4721,14 +4720,6 @@ public class Grid extends AbstractListing implements HasComponents, getState().sortDirs = directions.toArray(new SortDirection[0]); sortOrder.clear(); - if (order.isEmpty()) { - // Grid is not sorted anymore. - getDataCommunicator().setBackEndSorting(Collections.emptyList()); - getDataCommunicator().setInMemorySorting(null); - fireEvent(new SortEvent<>(this, new ArrayList<>(sortOrder), - userOriginated)); - return; - } sortOrder.addAll(order); sort(userOriginated); } diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java index 87d3c5ef11..04d7d338a7 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java @@ -42,11 +42,11 @@ import com.vaadin.data.provider.DataGenerator; import com.vaadin.data.provider.DataProvider; import com.vaadin.data.provider.GridSortOrder; import com.vaadin.data.provider.QuerySortOrder; -import com.vaadin.data.provider.SortOrder; import com.vaadin.data.provider.bov.Person; import com.vaadin.event.selection.SelectionEvent; import com.vaadin.server.SerializableComparator; import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.HeightMode; import com.vaadin.tests.util.MockUI; import com.vaadin.ui.Grid; @@ -286,13 +286,20 @@ public class GridTest { } @Test - public void clearSortOrder() { + public void clearSortOrder() throws Exception { Column column = grid.getColumns().get(1); grid.sort(column); grid.clearSortOrder(); assertEquals(0, grid.getSortOrder().size()); + + // Make sure state is updated. + Method stateMethod = grid.getClass().getDeclaredMethod("getState"); + stateMethod.setAccessible(true); + GridState state = (GridState) stateMethod.invoke(grid); + assertEquals(0, state.sortColumns.length); + assertEquals(0, state.sortDirs.length); } @Test -- cgit v1.2.3