Reputation: 15
enter image description hereHow to show multiline data in Vaadin Grid cell.
Tried out with \n with string but still showing in one line.
Upvotes: 0
Views: 736
Reputation: 5766
When adding the column, instead of using a ValueProvider
that returns a string, you can use a ComponentRenderer
and return a simple component where you can control the line break yourself
// linebreaks wont work like this
grid.addColumn(item -> "line1 \n line2");
// try this instead.
// or probable even better you could use the `Html` component from Vaadin
grid.addColumn(new ComponentRenderer<>(item -> {
Span span1 = new Span("line1");
Span span2 = new Span("line2");
return new VerticalLayout(span1, span2);
}));
You can also use a TemplateRenderer, which will use less memory than a ComponentRenderer, but has a little steeper learning curve (IMO).
Upvotes: 1
Reputation: 15
grid.addComponentColumn(item -> {
Span span1 = new Span("line1");
Span span2 = new Span("line2");
return new Div(span1, span2);
});
you can use this solution as well. both work fine.
Upvotes: 1