summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2014-06-25 11:16:46 +0300
committerJohn Ahlroos <john@vaadin.com>2014-06-27 09:45:44 +0300
commit8f71585df37d3f0e2e55ceac9e6abbaf2806855e (patch)
treef07d7a4d5b0a00523a1ca59c8f4f4db3c4e44d93 /server
parent67ad795d9e5761da1c788d4760edf290fc99391a (diff)
downloadvaadin-framework-8f71585df37d3f0e2e55ceac9e6abbaf2806855e.tar.gz
vaadin-framework-8f71585df37d3f0e2e55ceac9e6abbaf2806855e.zip
Allow turning sorting on/off for columns #13334
Change-Id: I161dfd2cd534cdf4fc13467811f77be7d8cbc339
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/components/grid/Grid.java8
-rw-r--r--server/src/com/vaadin/ui/components/grid/GridColumn.java18
2 files changed, 26 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/components/grid/Grid.java b/server/src/com/vaadin/ui/components/grid/Grid.java
index 0d7e799978..1ebf227330 100644
--- a/server/src/com/vaadin/ui/components/grid/Grid.java
+++ b/server/src/com/vaadin/ui/components/grid/Grid.java
@@ -30,6 +30,7 @@ import com.vaadin.data.Container;
import com.vaadin.data.Container.PropertySetChangeEvent;
import com.vaadin.data.Container.PropertySetChangeListener;
import com.vaadin.data.Container.PropertySetChangeNotifier;
+import com.vaadin.data.Container.Sortable;
import com.vaadin.data.RpcDataProviderExtension;
import com.vaadin.server.KeyMapper;
import com.vaadin.shared.ui.grid.ColumnGroupRowState;
@@ -253,6 +254,13 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier {
if (!columns.containsKey(propertyId)) {
GridColumn column = appendColumn(propertyId);
+ // Initial sorting is defined by container
+ if (datasource instanceof Sortable) {
+ column.setSortable(((Sortable) datasource)
+ .getSortableContainerPropertyIds().contains(
+ propertyId));
+ }
+
// Add by default property id as column header
column.setHeaderCaption(String.valueOf(propertyId));
}
diff --git a/server/src/com/vaadin/ui/components/grid/GridColumn.java b/server/src/com/vaadin/ui/components/grid/GridColumn.java
index fd504fdae3..634526ea7c 100644
--- a/server/src/com/vaadin/ui/components/grid/GridColumn.java
+++ b/server/src/com/vaadin/ui/components/grid/GridColumn.java
@@ -395,4 +395,22 @@ public class GridColumn implements Serializable {
grid.getPropertyIdByColumnId(state.id));
}
+ /**
+ * Should sorting controls be available for the column
+ *
+ * @param sortable
+ * <code>true</code> if the sorting controls should be visible.
+ */
+ public void setSortable(boolean sortable) {
+ checkColumnIsAttached();
+ state.sortable = sortable;
+ grid.markAsDirty();
+ }
+
+ /**
+ * Are the sorting controls visible in the column header
+ */
+ public boolean isSortable() {
+ return state.sortable;
+ }
}