diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2018-05-15 15:10:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-15 15:10:59 +0300 |
commit | a4e2d461d5781b6b69ebda0757cc1c7e3d871f1d (patch) | |
tree | a5902c853fe1ac10f9fe009747021dca1a852970 /server | |
parent | fad7b00016bf5308548b55c080fc272355a0f835 (diff) | |
download | vaadin-framework-a4e2d461d5781b6b69ebda0757cc1c7e3d871f1d.tar.gz vaadin-framework-a4e2d461d5781b6b69ebda0757cc1c7e3d871f1d.zip |
Fix Grid clearSortOrder not updating state (#10917)
Fixes #9074
Diffstat (limited to 'server')
-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 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<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 |