In Vaadin 8 you could just do the following for example to get a list of the columns in the order displayed on the screen.
String columnOrderPreference = ((List<Grid.Column>)grid.getColumns()).stream()
.map(Grid.Column::getId)
.collect(Collectors.joining(VALUE_SEPARATOR));
This was especially handy because you could then save that string and then call:
grid.setColumnOrder(columnOrderPreference.split(VALUE_SEPARATOR));
In Vaadin 14 (ignoring that getId()
should now use getKey()
) this is no longer possible because the getColumns()
list is now always returned in the order they were added and not the order in which they are ordered. You can still call setColumnOrder(...)
(with different parameters - list of grid.getColumnByKey(columnKey)
) but I cannot figure out how to get the list of columns in the order they are displayed.
This is especially useful for trying to save the column order the user has set/changed when they come back to the same page (with the Grid).