1
votes

Im trying to re-expand objects in a TreeTable after I have reset the container datasource for the TreeTable but i doesnt work. Has anyone tried this before? Where am I going wrong?

private void setTableDataSource() {
    Set<Object> expandedMap = new HashSet<Object>();
    if(table.getItemIds() != null && !table.getItemIds().isEmpty()){
        for(Object o : table.getItemIds()){         
            if(table.isCollapsed(o))
                expandedMap.add(o);
        }
    }       
    table.setContainerDataSource(ContactContainerFactory.createContainer(model.getParentModel()));
    table.setVisibleColumns(new String[]{"title", "operation", "id", "price"});
    table.setColumnHeaders(getTranslatedTableHeaders());        
    if(!expandedMap.isEmpty()){
        for(Object o : expandedMap){                
            table.setCollapsed(o, false);
        }
    }
}
1
Which vaadin version do you use ? Did you try with the last nightly build ? it seems that they added methods that allow you to collapse/expand all the elements : vaadin.com/forum/-/message_boards/view_message/…Zakaria
@Marthin Just as a hint but I'm pretty sure you have thought about the hash() and equals() method.nexus
Please update with an answer if you have solved this, Marthin!Aj Otto
@AjOtto i never got to a answer for this. I'm not working on that projekt anymore so I cant remeber how we solved it.Marthin

1 Answers

0
votes

I did it like this:

summary.getItemIds().forEach(id -> {
    summary.setCollapsed(id, false);
    summary.getChildren(id).forEach(child -> {
        summary.setCollapsed(child, false);
    });
});

Where summary is the tree table. This only works on a 2 level table but could be done in a recursive method.