简体   繁体   中英

How to show multiline data on Vaadin Grid cell of a column

enter image description here How to show multiline data in Vaadin Grid cell.

Tried out with \\n with string but still showing in one line.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM