5

Looks like GeneratedPropertyContainer does not exist in Vaadin 8.

How can we add a generated column to Vaadin 8 Grid? I appreciate if you can provide an example.

turgos
  • 1,464
  • 1
  • 17
  • 28
  • 1
    Did you get a chance to check the [docs](https://vaadin.com/docs/-/part/framework/components/components-grid.html#components.grid.generatedcolumns)? – Morfic Apr 07 '17 at 10:44
  • I didn't see Vaadin 8 version of that page before.Thank you for sharing Morfic. – turgos Apr 10 '17 at 01:17

2 Answers2

10

If you pass the bean class to the constructure of Grid then it will add all properties as columns to the grid.

If you want to only have some properties as columns then don't pass the class to the constructor and add your columns manually like this:

grid.addColumn(Address::getStreet);
grid.addColumn(Address::getHouseNumber);
grid.addColumn(Address::getPostalCode);
grid.addCOlumn(Address::getCity);

If you want to add a generated column just add it with addColumn

grid.addColumn(address -> {
  // put your calculations for the column here
  return address.getStreet() + " " + address.getHouseNumber();
});
Mihael
  • 364
  • 2
  • 4
0

A generated column would work like this:

grid.addColumn(address->address.getStreet()+" "+address.getHouseNumber()).setCaption("Street");
Armando Perea
  • 499
  • 2
  • 6
  • 18