Vaadin 8 Grid

Hi,
on https://vaadin.com/docs/-/part/framework/components/components-grid.html
you write:

Grid grid = new Grid<>(Person.class);
grid.getColumn(“birthDate”).setWidth(“100px”);
grid.setItems(people);

The grid.getColumn(“birthDate”)
does not work. I get a NullPointerException.

Hi,

does your Person bean have a birthDate property?

-Olli

yes

Column<Person, String> nameColumn = grid.addColumn(Person::getName)
.setCaption(“Name”);
System.out.println(nameColumn.getId());

This returns null

How to add a column otherwise?

Hi,

I think that’s because you’re adding the column with a method reference. You don’t get an id for the column in that case, only an internal generated id.

-Olli

There are quite a few overloads of that method:
https://vaadin.com/api/8.1.1/com/vaadin/ui/Grid.html#addColumn-java.lang.String-

but I’m not sure where you actually need that id value there.

-Olli

I want to use:

HeaderRow groupingHeader = grid.prependHeaderRow();
HeaderCell personCell = groupingHeader.join(groupingHeader.getCell(“name”),
groupingHeader.getCell(“birthDate”));
personCell.setText(“Person”);

But I can not make it work.

Have you tried using the version of groupingHeader that takes Grid.Column instead?

-Olli

It works! Thank you very much!

Good to hear :slight_smile: