Vaadin 8 - Grid column with row index

How can we add a generated column with row indexes to Vaadin 8 Grid?


List people = Arrays.asList(
new Person(“Nicolaus Copernicus”, 1543),
new Person(“Galileo Galilei”, 1564),
new Person(“Johannes Kepler”, 1571));

    // Create a grid bound to the list
    Grid<Person> grid = new Grid<>();
    grid.addColumn(Person -> people.indexOf(Person) + 1);
    grid.addColumn(Person::getBirthYear).setCaption("Year of birth");

[/code]If you have, for example, a list of objects you can do it as in example above.
Hopefully it helps,



Thanks Anastasia for your example.

In Vaadin 7, I used GeneratedPropertyContainer to create row index, so whenever I sorted the column, the topmost row is always row index 1 and bottommost row is always row count.
But with your example, the row index is static.


For Vaadin Flow, [this]
( is how it can be done, and also works when the user sorts the grid. Cheers