can one right align components in a HorizontalLayout component cell of a TreeGrid component column?
Hello! First of all thank you for your work.
- Vaadin Framework version - 8.12.3
- Browser version - chrome 90.0.4430.212
- Description of the bug
I have a TreeGrid with 2 component columns. The first component column contains a HorizontalLayout with a Label and a Button. The second component column contains a HorizontalLayout with a Button. I was not able to right align the Button in the first component column. Is it doable?
Thank you!
- Minimal reproducible example
TreeGrid<Object> treeGrid = new TreeGrid<>();
treeGrid.setSizeFull();
treeGrid.addComponentColumn(vp -> {
Button button = new Button("button");
HorizontalLayout cell = new HorizontalLayout(new Label("label"), button);
cell.setSizeFull();
cell.setExpandRatio(button, 1.0f);
cell.setComponentAlignment(button, Alignment.MIDDLE_RIGHT);
return cell;
}).setCaption("st column").setExpandRatio(1).setId("st column");
treeGrid.addComponentColumn(vp -> new HorizontalLayout(new Button("some other button")))
.setCaption("nd column").setId("nd column").setWidth(200.0d);
TreeData<Object> objectTreeData = new TreeData<>();
objectTreeData.addRootItems(new Object());
treeGrid.setDataProvider(new TreeDataProvider<>(objectTreeData));
window.setContent(treeGrid);
UI.getCurrent().addWindow(window);
window.center();
window.setWidth("40%");
window.setHeight("40%");```
This is technically a missing feature in how TreeGrid and ComponentRenderer play together, but I posted a workaround to the corresponding question in StackOverFlow. I'll have to think about whether it would be possible to add support for this use case in the framework itself.
thank you @Ansku ! probably the undefined width on the node helps the grid to correctly calculate the width of the column based on the most wide cell. when i use width 100% on the node and width 100% on the HorizontalLayout my first column is as wide as the widest cell that does not contain a HorizontalLayout.
Yes, using CSS with columns always interferes with those calculations. It's part of the reason why it's not a trivial thing to add a built-in support for the feature.