Vaadin 8 Grid Column with Row Index

How do you go about creating a Grid column with a Row Index, similar to a V7 Tables setRowHeaderMode(RowHeaderMode.INDEX) .

Adding a column with a running variable

addColumn(profile -> { return row++; }) or using CSS:

.v-grid-body{ counter-increment: index; } .v-grid-cell.row-index:before{ counter-increment: index; content: counter(index); } do not work because DOM elements are reused as you scroll the Grid. With the V7 Grid you could use a GeneratedPropertyContainer. I’m looking for a
strictly
V8 Grid solution.

Here is yet another ugly hack:

// Init data..
ListDataProvider<Bean> listDataProvider = DataProvider.ofCollection(...);
grid.setDataProvider(listDataProvider);

// Hack? #ugly
List<Bean> listOfList = new ArrayList<>(listDataProvider.getItems());

// Here we go!
grid.addColumn(listOfList::indexOf);

Thanks. But, it doesn’t really work with a CallBackDataProvider, that is when row indices are actually useful.

From one side, not having this natively implemented in Grid means a good performance improvment, because Grid does not need to keep track of beans. Otherwise how it would keep index of each bean and reuse it, without occuping a big memory footprint with a big list of indexes and bean IDs.

Probably you can implement the index on the backend level? Or at least make a sequential ID that can be mapped one-to-one to an index, such as:

grid.addColumn(c -> c.getId() - ID_CONSTANT);

A backend numbering sequence is my last resort, because it means significant amendments to queries (MySQL requires it’s own hack to generate a row number in a query) and won’t work with filtered data.

I haven’t studied the internals of Grid, but I would presume it already tracks row indices because CallBackDataProviders have offset and limit parameters to load data as you scroll. This means that the Grid, to some extent, must be aware of the indices of start and end rows are visible at that moment.

Hi,

I need to add a column to my vaadin 8 grid showing the row index, a backend numbering sequence for me is impossible.

Is there any news on this topic?