I don’t see an issue, it renders exactly as configured. You have specified that the columns take only as much space as their need therefore there is still space left. Grid is by default 100% wide
I wanted grid to take full possible width without shrinking, but wrapping content if content’s width is smaller than grid’s width. Actually I want to make all columns have width just enough to render all content, but using no more empty space
You have to set flex grow 1 for the column that should take the full space. And it should not be auto width. Also, if the component should take the available column space, it also needs to be set to dynamic width.
For instance:
public class TestView extends VerticalLayout {
public TestView() {
setSizeFull();
Grid<Integer> grid = new Grid<>();
grid.setWidthFull(); // dynamic width
// grid.setWidth("700px"); // some fixed width also works
grid.addColumn(i -> i.toString()).setHeader("Index").setFlexGrow(0).setAutoWidth(true);
grid.addComponentColumn(i -> new TextField()).setHeader("TF").setFlexGrow(0).setAutoWidth(true);
grid.addComponentColumn(i -> {
MultiSelectComboBox<String> box = new MultiSelectComboBox<>();
box.setItems(List.of("Value A", "Value B", "Value C", "Value D", "Value E", "Value F", "Value G"));
box.setValue(List.of("Value A", "Value B", "Value C", "Value D", "Value E", "Value F", "Value G"));
box.setAutoExpand(AutoExpandMode.BOTH);
box.setWidthFull();
return box;
}).setHeader("MSCB").setFlexGrow(1);
grid.addComponentColumn(i -> new Checkbox()).setHeader("CB").setFlexGrow(0).setAutoWidth(true);
grid.setItems(IntStream.range(0, 10).boxed().toList());
add(grid);
}
}
Yes, that seems to be not possible out of the box. There are two reasons
the grid has set an align-self: stretched (similar to the form layout). This makes it always full width inside a flex layout. Unfortunately, when setting it to start, the grid becomes a single pixel wide. This is because of 2.
The vaadin-scroller is set to position: absolute. Due to that, the width calculation of the grid breaks, when it does not stretch itself or has a fixed width. You can set the scroller to position: relative and height: 100%using shadow dom styling, but I do not know, if that breaks anything inside the displayment.
I will create a github issue for this use case. Can you check, if that works for you and, if there are any issues resulting out of this workaround, post them here please?
Not sure if that will affect the scroller inside the grid, but since that will be a global styling, the better way will be to create the following file inside your themes folder: