How can we add a generated column with row indexes to Vaadin 8 Grid?
Hi,
[code]
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.setItems(people);
grid.addColumn(Person -> people.indexOf(Person) + 1);
grid.addColumn(Person::getName).setCaption("Name");
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,
Regards,
Anastasia
Hello,
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.
Thanks.
For Vaadin Flow, [this]
(https://stackoverflow.com/a/62061436/3441504) is how it can be done, and also works when the user sorts the grid. Cheers