1

I would like to save the column order the user has set/changed when they come back to the same page in Grid.

I read this issue - How do you get the column order for the Grid in Vaadin 14?

Is this issue fixed in Vaadin 23? If there is any solution, please share with me.

General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

1

Yes, this is possible with flow 23. Here the listeners I use to save column order and width

protected List<Grid.Column<T>> newColOrder= null;
grid.addColumnReorderListener((event) ->
{
    newColOrder= event.getColumns();
    persistColumns();
});
grid.addColumnResizeListener((event) ->
{
    persistColumns();
});

And the persistColumn method:

List<Grid.Column<T>> cols= newColOrder != null ? newColOrder : grid.getColumns();
for (Grid.Column<T> col : cols)
{
    boolean isHidden= !col.isVisible();
    String colWidth= col.getWidth();
    String colID= col.getKey();
    gcs.add(new GridColumnStatus(isHidden, colWidth, colID));
}
André Schild
  • 4,592
  • 5
  • 28
  • 42
  • I tried your code, but I am getting a compiler error "The method getColumns() is undefined for the type ComponentEvent" from the line newColOrder=event.getColumns(); – Jennifer Nam Apr 27 '22 at 14:55
  • How do you define the grid? https://vaadin.com/api/platform/23.0.7/com/vaadin/flow/component/grid/Grid.html#getColumns() – André Schild Apr 27 '22 at 18:51
  • Andre, I added the extra line to cast event type to ColumnReorderEvent as below; event type is ComponentEvent by default. grid.addColumnReorderListener((event) -> { ColumnReorderEvent aColumnReorderEvent = (ColumnReorderEvent)event; List newColOrder = aColumnReorderEvent.getColumns(); ... } Thank you for your comment. :) – Jennifer Nam Apr 29 '22 at 14:13