alwaysRecalculateColumnWidths = true doesn't work for new items created thr

Hi all,
The experimental feature
alwaysRecalculateColumnWidths
works fine when adding items through a button:

  • A new item will be added with a larger text
  • The column gets as large as the text
  • A scrollbar is show as the columns don’t fit in the table width.
    See the attachment ClickButton.jpg

But when adding an item through a node expand listener (click on the expand icon) then the column widths won’t be recalculated:

  • A new item will be added with a larger text
  • The column should also get as large to fit the text, but that isn’t the case. The column width stays the same.
    See the attachment ExpandNode.jpg

Here a full example:

[code]
package com.example.autoscaletest;

import com.vaadin.annotations.Theme;
import com.vaadin.data.Item;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Tree.ExpandEvent;
import com.vaadin.ui.Tree.ExpandListener;
import com.vaadin.ui.TreeTable;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings(“serial”)
@Theme(“autoscaletest”)
public class AutoscaletestUI extends UI {

protected static final String FIRST = "first";
protected static final String SECOND = "second";
private TreeTable tt;

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);

    tt = new TreeTable() {
        {
            alwaysRecalculateColumnWidths = true;
        }
    };
    tt.setWidth("200px");
    tt.addContainerProperty(FIRST, String.class, "");
    tt.addContainerProperty(SECOND, String.class, "");
    addItem(FIRST);
    
    // Column doesn't get larger
    tt.addExpandListener(new ExpandListener() {
        @Override
        public void nodeExpand(ExpandEvent event) {
            addItem(FIRST + FIRST + FIRST);
        }
    });
    
    // Column gets larger
    Button button = new Button("Add item");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            addItem(FIRST + FIRST + FIRST);
        }
    });
    layout.addComponent(tt);
    layout.addComponent(button);
}

private void addItem(String text) {
    Object addItem = tt.addItem();
    Item item = tt.getItem(addItem);
    item.getItemProperty(FIRST).setValue(text);
    item.getItemProperty(SECOND).setValue(SECOND);
}

}
[/code]What has to be done to get the column larger when pressing the expand icon?

Any help is appreciated :slight_smile:
17910.jpg
17911.jpg

Did you find a solution to this? I’ve just encountered the same thing - column widths are calculated based on the root items, and don’t change when you expand them. Making a change to one of the newly expanded children does cause a resize, however.