summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/Grid.java23
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java9
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());
+ }
}