How to apply compact to a grid in Vaadin 14 flow through a button

Viewed 104

In Vaadin 14 Flow I have the following code:

Grid grid = new Grid();
setupGrid(grid);

Button compactButton = new Button("Compact", 
    click -> grid.addThemeVariants(GridVariant.LUMO_COMPACT));
Button normalButton = new Button("Normal", 
    click -> grid.removeThemeVariants(GridVariant.LUMO_COMPACT));

The issue is when I click on the above buttons only the header of the grid seems to be redrawn when the buttons are clicked, the rows below the header (all the rows of the table) do not appear to be affected. They seem to stay at whatever variant they were initially set at when the screen was initially drawn (other than the header). Is there a way to programmatically adjust the theme of the grid through a button?

1 Answers

You can call grid.getDataProvider().refreshAll(); after changing the theme for it to be applied to all rows.

Related