I'm migrating from Vaadin 7 Table to Vaadin 8 Grid. In the Vaadin 7 Table we used IndexedContainer or Container with Property and could access the table cell value with IndexedContainer.getItem(propertyId).getItemProperty(itemId).getValue();
or Container.getContainerProperty(itemId, propertyId).getValue()
.
The content of a Vaadin 8 Grid is set via Grid.setItems(Collection<T>)
. I found how to access the columns - Grid.getColumns()
- and the data provider - Grid.getDataProvider()
. But I did not find a way to combine them and get the value of a specific cell...
Is there a way to access a cell value in a similar way when using a Vaadin 8 Grid?
Update:
I currently try to figure out the way in accessing data through Grid methods. Currently I have the Vaadin 7 Table code where we access the cell values in a generic way to export the data to e.g. Excel, CSV or PDF:
Table table = ...; /* Is passed in while initializing and is used as kind of black box in the exporter */
// Compiling cell values
Object[] visibleColumns = table.getVisibleColumns();
Container container = table.getContainerDataSource();
for (Object itemId : container.getItemIds())
{
for (Object propertyId : visibleColumns)
{
Property property = container.getContainerProperty(itemId, propertyId);
Object value = property == null ? null : property.getValue();
buildCell(value);
}
}
In Vaadin 8 I have the Grid and I tried to adapt:
Grid grid = ...; // Passed in while initializing
// Compiling cell values
List visibleColumns = new ArrayList();
List columns = table.getColumns();
for(Iterator iterator = columns.iterator(); iterator.hasNext();)
{
Column column = iterator.next();
if (!column.isHidden())
{
visibleColumns.add(column);
}
}
// The Grid gets a Collection set as items, so I assume the rows should be ListDataProvider
ListDataProvider listContainer = (ListDataProvider)grid.getDataProvider();
Collection items = listContainer.getItems();
for (/* Now I should be able to get the stored values in each row, but I assume I need the data types ... */)
{
for (Column column : visibleColumns)
{
String propertyId = column.getId(); // Could be null if no ID is given
/* At least here I'd like to have access to the cell value */
}
}