In my Vaadin 7 app, I call grid.recalculateColumnWidths(); after loading most grids. I do this because when I was refreshing one particular Grid, I noticed the column width was not changing. This fixed it with this one particular Grid, and probably a few others, but not with all grids. The documentation does not really explain a few things, and I was hoping someone could clarify some things so I can fix the problem:
- When is it triggered? In other words, in the cases where it does not work, could it be a timing issue? For Vaadin Flow, I see some people advising doing something like
grid.getElement().executeJs("setTimeout(() => { this.recalculateColumnWidths() }, 0)");, so I guess this is a long-standing issue. Also, if you look at the low-level API, you will see that it clearly says that you cannot rely on proper columns widths after calling this function, as it is not done immediately. When I step into it in the debugger, it looks like it adds it to a queue of actions to complete later, so that seems to confirm things. How can I improve my chances of the resize being triggered? - How does it handle columns where I explicitly set the width? If this is documented someplace (in API docs or in some posting someplace), I could not find it. When I stepped into the debugger, it was kind of hard to determine for sure.
- If I added a button to force a resizing, calling this
recalculateColumnWidths()method, similar to what some users did in Vaadin 14 here, would it work? So let's say we initialize the width to one value (so we purposely truncate some columns, forcing them to make the column bigger), and we want to fully show all content in all columns when they click this button, is there a way to do that? Maybe clear all explicit column sizes and let normal resize logic work?