How make Grid render a Label Component ?

Hi,

I’am trying to make Grid render a Label component, but it is happening.

How can i do this ?

Thanks

33604.png

Hi Ramon,

you have to specify the Renderer for column to display a Label as a component.

<
https://vaadin.com/docs/-/part/framework/components/components-grid.html#components.grid.renderer
>
For example in Vaadin8 you can do it like this:

 Grid<Person> grid = new Grid<>();
/*Initialization */
grid.addColumn(p -> new Label("Label"), new ComponentRenderer()); // will display the Label

Hopefully it helps : ),

Best regards,
Anastasia

It worked for me. Thanks!

There’s a way to do something like grid.addColumn(p → new Label(“Label”), new ComponentRenderer()); in vaadin 7.7.9 ? Or i still need to add renderers ?

Thanks

There’s the ComponentRenderer add-on: https://vaadin.com/directory#!addon/componentrenderer

-Olli

Thanks

Anastasia Smirnova:
Hi Ramon,

you have to specify the Renderer for column to display a Label as a component.

https://vaadin.com/docs/-/part/framework/components/components-grid.html#components.grid.renderer
For example in Vaadin8 you can do it like this:

Grid<Person> grid = new Grid<>();
/*Initialization */
grid.addColumn(p -> new Label("Label"), new ComponentRenderer()); // will display the Label

Hopefully it helps : ),

Best regards,
Anastasia

How can i do this in Vaadin 14? Thanks!

Carp Daniela-Iuliana:
How can i do this in Vaadin 14? Thanks!

grid.addComponentColumn(item -> new Label("Label"));

you can use item-specific values inside that lambda: grid.addComponentColumn(item -> new Label(item.getName()));

grid.addComponentColumn(item -> ...) is a short form for grid.addColumn(new ComponentRenderer<>(item -> ...));
Further documentation on grid column renderers: https://vaadin.com/docs/v14/flow/components/tutorial-flow-grid.html#using-component-renderers

Kaspar Scherrer:

Carp Daniela-Iuliana:
How can i do this in Vaadin 14? Thanks!

grid.addComponentColumn(item -> new Label("Label"));

you can use item-specific values inside that lambda: grid.addComponentColumn(item -> new Label(item.getName()));

grid.addComponentColumn(item -> ...) is a short form for grid.addColumn(new ComponentRenderer<>(item -> ...));
Further documentation on grid column renderers: https://vaadin.com/docs/v14/flow/components/tutorial-flow-grid.html#using-component-renderers

Thank you!!