Warm tip: This article is reproduced from serverfault.com, please click

Vaadin Crud UI. Axes are not sorted correctly

发布于 2021-12-06 13:32:27

Why am I getting my axes like this? How can I sort them currectly. I'm using Vaadin Crud component (not Grid).

Crud<OpvUser> crud = new Crud<>(OpvUser.class, createUserEditor());
crud.getGrid().addItemDoubleClickListener(e -> crud.edit(e.getItem(), Crud.EditMode.EXISTING_ITEM));

UserDataProvider dataProvider = new UserDataProvider();
crud.setDataProvider(dataProvider);
dataProvider.refreshAll();
     .....
crud.getGrid().setSortableColumns();
crud.getGrid().removeColumnByKey("password");
crud.addThemeVariants(CrudVariant.NO_BORDER);
add(crud); 

enter image description here

Questioner
Sayer Arab
Viewed
0
Sascha Ißbrücker 2021-12-07 02:55:50

I assume that you want to change the order of the columns, as that is one thing that stands out from the image you posted.

The Crud component builds a Grid internally, with columns automatically generated from the properties that exist in the bean class that you pass into the constructor (OpvUser in your case). Depending on how the properties in the bean class are defined, the order of colums might not be suitable. If you want to change the order of columns, you can call setColumnOrder on the grid. For your example, that should look something like this:

Grid<OpvUser> grid = crud.getGrid();
grid.setColumnOrder(
  // Columns keys are the exact property names of the bean class
  grid.getColumnByKey("id"),
  grid.getColumnByKey("firstName"),
  grid.getColumnByKey("lastName"),
  grid.getColumnByKey("email")
);

See the Crud docs for a full example, as well as the Grid API docs