Browse Source

Fix Grid column adding to set column sortable correctly (#17446)

Change-Id: I2cfc41f9fab39c387306e89fb18de75c413a7817
tags/7.4.4
Teemu Suo-Anttila 9 years ago
parent
commit
1469abf926

+ 15
- 8
server/src/com/vaadin/ui/Grid.java View File

@@ -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;
}


+ 9
- 0
server/tests/src/com/vaadin/tests/server/component/grid/GridColumns.java View File

@@ -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());
}
}

Loading…
Cancel
Save