diff options
-rw-r--r-- | server/src/main/java/com/vaadin/ui/Grid.java | 11 | ||||
-rw-r--r-- | server/src/test/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 887a43f5c8..e78733701c 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<T> extends AbstractListing<T> 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<T> extends AbstractListing<T> 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<String, ?> 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 |