Possible bug in GridPro when re-ordering columns, recalculateColumnWidths fails

I have a layout bug in GridPro that perhaps is related to either event chaining or timing.
It occurs after creating new columns, trying a recalculateColumnWidths() doesn’t help if done in the same event.

I have a Select component that, during a valueChange event, triggers new columns creation and layout in the GridPro grid. After creating new columns I call recalculateColumnWidths() in the same valueChange event from the Select. The result is a GridPro with empty space between the rows, but when I either click a button or let a timer fire, then the call to recalculateColumnWidths() works fine. Here is a bit of code to give an idea:

    startYear.addValueChangeListener(evt -> {
        itemSubView.resetGrid(makeParams());
        itemSubView.genericGrid.recalculateColumnWidths();      // Doesn't work

        timer.setStartTime(3);
        timer.start();
    });

    refreshBtn.addClickListener(evt -> {
        itemSubView.genericGrid.recalculateColumnWidths();      // Now it works
    });

    timer.addTimerEndEvent(ev-> {
        System.out.println("tick");
        itemSubView.genericGrid.recalculateColumnWidths();      // Now it works
    });

The test is a lot of code so you have to go here and download the code to recreate it, use the “GridPro Generator Test” menu and try changing the Select values:

Is it me or is there some kind of race condition in GridPro?

Here is how it look when it fails:

Compare that to the picture in the repo or download and try the demo.

Best way to report issues is our GitHub: Issues · vaadin/web-components · GitHub

Maybe this one is related: Grid recalculateColumnWidths doesn't recalculate on first attempt · Issue #1864 · vaadin/vaadin-grid · GitHub

2 Likes

It doesn’t seem to be related to the “not on first attempt” in the link. I can completely avoid doing a recalculateColumnWidths when recreating and reordering the columns and in that case I still get the failed layout until I click the button, which is then the first call to recalculateColumnWidths.

I will report the (possible) bug to the GitHub link, thanks.

1 Like