Grid ... sorting not possible

Hi,

I am using Grids in my Vaadin WebApp. In the tutorial and the Book sorting seems possible out of the Box. When I click on the header, nothing happens.

Would could be the reason? Did I miss something.

Here is the Init-Code, Nothing special,

public void init(BeanItemContainer container) {
setFooterVisible(true);
setContainerDataSource(container);
setSizeFull();
setImmediate(true);

    controllerTableSelection = new KontoBuchungGridSelectionController();
    controllerTableSelection.init(this);
    
    setColumnOrder(columnOrder);
    removeAllColumns();
    for (Object propertyId : columnOrder) {
        addColumn(propertyId);
    }
    
    getColumn(KontoBuchung.Attributes.belegdatum.name()).setWidth(150d);
    getColumn(KontoBuchung.Attributes.buchungsdatum.name()).setWidth(150d);

// getColumn(KontoBuchung.Attributes.vorhabenId.name()).setWidth(150d);
// getColumn(KontoBuchung.Attributes.kostenartId.name()).setWidth(150d);

    getColumn(KontoBuchung.Attributes.belegdatum.name()).setRenderer(new DateRenderer(new SimpleDateFormat(DateFormatUtil.GERMAN_DATE_PATTERN)));
    getColumn(KontoBuchung.Attributes.buchungsdatum.name()).setRenderer(new DateRenderer(new SimpleDateFormat(DateFormatUtil.GERMAN_DATE_PATTERN)));
    getColumn(KontoBuchung.Attributes.kurs.name()).setRenderer(new NumberRenderer(DecimalFormatUtil.germanDecimalFormat));
    getColumn(KontoBuchung.Attributes.eingang.name()).setRenderer(new NumberRenderer(DecimalFormatUtil.germanDecimalFormat));
    getColumn(KontoBuchung.Attributes.eingangeur.name()).setRenderer(new NumberRenderer(DecimalFormatUtil.germanDecimalFormat));
    getColumn(KontoBuchung.Attributes.ausgang.name()).setRenderer(new NumberRenderer(DecimalFormatUtil.germanDecimalFormat));
    getColumn(KontoBuchung.Attributes.ausgangeur.name()).setRenderer(new NumberRenderer(DecimalFormatUtil.germanDecimalFormat));
    
    getColumn(KontoBuchung.Attributes.vorhabenId.name()).setRenderer(new HtmlRenderer(), new JPAConverter<Vorhaben>(Vorhaben.class));
    getColumn(KontoBuchung.Attributes.kostenartId.name()).setRenderer(new HtmlRenderer(), new JPAConverter<Kostenart>(Kostenart.class));
    
    DateFilter.createFilter(this, this, KontoBuchung.Attributes.belegdatum.name());
    DateFilter.createFilter(this, this, KontoBuchung.Attributes.buchungsdatum.name());
    
    BigDecimalSumFooter.create(this, this, KontoBuchung.Attributes.eingang.name());
    BigDecimalSumFooter.create(this, this, KontoBuchung.Attributes.eingangeur.name());
    BigDecimalSumFooter.create(this, this, KontoBuchung.Attributes.ausgang.name());
    BigDecimalSumFooter.create(this, this, KontoBuchung.Attributes.ausgangeur.name());
    
    CountSumFooter.create(this, this, KontoBuchung.Attributes.kontoLfnr.name(), "Anzahl:");
    
    container.addItemSetChangeListener(new ItemSetChangeListener() {
        private static final long serialVersionUID = 2674115953987436975L;

        @Override
        public void containerItemSetChange(ItemSetChangeEvent event) {
            recalculateColumnWidths();
        }
    });
}

Hi Andre,

At a quick glance at the code this might be a bug - when the data source is set those columns that correspond to sortable properties in the container are indeed set sortable, but if you remove columns and add new ones, they are left as non-sortable (the default) :frowning:

EDIT: Opened ticket
17227
.

Brillant, I help me with this workaround:

List colList = getColumns();
for (Column column : colList) {
boolean found = false;
for (Object propertyId : columnOrder) {
if(propertyId.equals(column.getPropertyId())) {
found = true;
break;
}
}
if(!found) {
removeColumn(column.getPropertyId());
}
}

Could be better to use a ArrayList instead of an Object-Array.

Thx a lot for helping me

You can also do manually when adding columns:

removeAllColumns();
for (Object propertyId : columnOrder) {
    boolean sortable = container.getSortableContainerPropertyIds().contains(propertyId);
    addColumn(propertyId).setSortable(sortable);
}

Hi,

This bug has been fixed in Vaadin master branch. You can expect the fix to be available in a maintenance release soon. Thank you for the bug report. If there are any further issues, just respond to this thread.

//Teemu