vaadin-grid

Hi,
I am trying to use vaadin-grid component in my code. I tried to use the example source code to display grid item detail. But I have problems with ComponentRenderer. I am getting error: “The type ComponentRenderer is not generic; it cannot be parameterized with arguments <>” for the source code from example:

Grid grid = new Grid<>();
grid.setItems(people);

grid.addColumn(new ComponentRenderer<>(person → {
if (person.getGender() == Gender.MALE) {
return new Icon(VaadinIcons.MALE);
} else {
return new Icon(VaadinIcons.FEMALE);
}
})).setHeader(“Gender”);

Could you please help me with the error? Or is there any other option how to show item details for a grid item?

Thank you very much.

Tomas

Hi Tomas,

The code you posted doesn’t actually set the item details of a row, it only sets an icon component to a column. The error you are having is related to the fact that your Grid is not using generics:

// instead of
Grid grid = new Grid<>(); 

// it should be
Grid<Person> grid = new Grid<>();

To set item details for the rows, you have to use the setItemDetailsRenderer method from Grid. You can see some examples here: https://vaadin.com/components/vaadin-grid/java-examples/item-details

Hi Gilberto,

thank you very much for your quick answer. The problem was that I used import from com.vaadin.ui.renderers.ComponentRenderer instead of com.vaadin.flow.data.renderer.ComponentRenderer.

But now I have another error: “Cannot infer type arguments for ComponentRenderer<>”

my code:

	Grid<Person> grid = new Grid<>();
	grid.setItemDetailsRenderer(new ComponentRenderer<>(Person::new));

Got it, it must be

grid.setItemDetailsRenderer(new ComponentRenderer<>(PersonCard::new));

which has the constructor with Person paramater.

Thanks a lot.

T.

Hi Gilberto,

I have a question about Vaadin 8. Is it possible to have the row detail functionality also in Vaadin 8?

Thank you.

T.

Yes!

For V8 the API is a bit different though. You have to call setDetailsGenerator.