diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-04-13 10:51:15 +0300 |
---|---|---|
committer | Markus Koivisto <markus@vaadin.com> | 2015-04-15 11:59:03 +0300 |
commit | 1469abf9264571791f273243a53b7a454af5f859 (patch) | |
tree | efd425543c10d05d4f909a62ce27da5ddcfdf8f7 /server | |
parent | ebde3be659ee9e536b05aa4a6418214952360d3b (diff) | |
download | vaadin-framework-1469abf9264571791f273243a53b7a454af5f859.tar.gz vaadin-framework-1469abf9264571791f273243a53b7a454af5f859.zip |
Fix Grid column adding to set column sortable correctly (#17446)
Change-Id: I2cfc41f9fab39c387306e89fb18de75c413a7817
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/Grid.java | 23 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java | 9 |
2 files changed, 24 insertions, 8 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index ee7da1e36c..b8b5040b13 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -31,7 +31,6 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -2840,13 +2839,15 @@ public class Grid extends AbstractComponent implements SelectionNotifier, setFrozenColumnCount(columns.size()); } - // Update sortable columns - if (event.getContainer() instanceof Sortable) { - Collection<?> sortableProperties = ((Sortable) event - .getContainer()).getSortableContainerPropertyIds(); - for (Entry<Object, Column> columnEntry : columns.entrySet()) { - columnEntry.getValue().setSortable( - sortableProperties.contains(columnEntry.getKey())); + // Unset sortable for non-sortable columns. + if (datasource instanceof Sortable) { + Collection<?> sortables = ((Sortable) datasource) + .getSortableContainerPropertyIds(); + for (Object propertyId : columns.keySet()) { + Column column = columns.get(propertyId); + if (!sortables.contains(propertyId) && column.isSortable()) { + column.setSortable(false); + } } } } @@ -3507,6 +3508,12 @@ public class Grid extends AbstractComponent implements SelectionNotifier, column.setHeaderCaption(SharedUtil.propertyIdToHumanFriendly(String .valueOf(datasourcePropertyId))); + if (datasource instanceof Sortable + && ((Sortable) datasource).getSortableContainerPropertyIds() + .contains(datasourcePropertyId)) { + column.setSortable(true); + } + return column; } diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java index fda662e4d9..dbc8cfff3c 100644 --- a/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java +++ b/server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java @@ -302,4 +302,13 @@ public class GridColumns { } return null; } + + @Test + public void testAddAndRemoveSortableColumn() { + boolean sortable = grid.getColumn("column1").isSortable(); + grid.removeColumn("column1"); + grid.addColumn("column1"); + assertEquals("Column sortability changed when re-adding", sortable, + grid.getColumn("column1").isSortable()); + } } |