I wrote some sample code to test resizing column widths based on a column becoming full with text and using the built-in Grid column width recalculation API.
I set up a button to update the text in one of the columns and then recalculate the column widths. Unfortunately, it doesn’t recalculate after updating the text. However, if I click the button a second time, the recalculate does work.
Here’s my sample code to demonstrate:
public Grid2() {
ThreeString ts1 = new ThreeString("111", "222", "333");
ThreeString ts2 = new ThreeString("444", "555", "667");
Collection<ThreeString> itemList = new ArrayList<ThreeString>();
itemList.add(ts1);
itemList.add(ts2);
Grid<ThreeString> grid1 = new Grid<>();
grid1.setHeightByRows(true);
grid1.setItems(itemList);
grid1.addColumn(ThreeString::getA).setHeader("First String").setSortable(true).setResizable(true)
.setAutoWidth(true);
grid1.addColumn(ThreeString::getB).setHeader("Second String").setSortable(true).setResizable(true)
.setAutoWidth(true);
grid1.addColumn(ThreeString::getC).setHeader("Third String").setSortable(true).setResizable(true)
.setAutoWidth(true);
add(grid1);
Button button = new Button("Add Text");
button.addClickListener(event -> {
ts2.setB("This string became really long and it will cause the cell to grow its width and not truncate.");
grid1.getDataProvider().refreshAll();
grid1.recalculateColumnWidths();
});
add(button);
}
I assume I’m calling the API to recalculate at the wrong time (i.e. in the button click listener). How should I be calling the API to recalculate the widths so that it updates when I click the button the first time?
If this issue with grid.getDataProvider().refreshAll(); grid.recalculateColumnWidths(); can still be reproduced with latest 14.1.23 then it should be reported in [vaadin-grid-flow]
(https://github.com/vaadin/vaadin-grid-flow/issues) with the code to reproduce it.
If this issue with grid.getDataProvider().refreshAll(); grid.recalculateColumnWidths(); can still be reproduced with latest 14.1.23 then it should be reported in [vaadin-grid-flow]
(https://github.com/vaadin/vaadin-grid-flow/issues) with the code to reproduce it.
I confirmed today that the issue persists in 14.1.23.