简体   繁体   中英

Why is vaadin-grid not showing links (anchors)?

I am trying to have a table column with links in my Vaadin 10, Spring-boot application.

I am displaying data in a grid as follows:

Grid<Person> grid = new Grid<>();
UI.getCurrent().getRouter();

grid.addColumn(
   p -> new Anchor(UI.getCurrent().getRouter().getUrl(
                    PersonView.class, p.getName()),
                   p.getName())).setHeader("Name");
grid.addColumn(p ->   
   p.getProjects().size()).setHeader("#Projects");

grid.setItems(repo.findAll());
add(grid);
setSizeFull();

But the grid column with the links is only displaying text like Anchor@XXXXXXX

The problem is, that the column data is interpreted as value and not as component. You need to tell the grid, that it should use a renderer, which displays components and does not wrap them.

This can be done using a ComponentRenderer .

If you modify your column as follows, it works:

grid.addColumn(new ComponentRenderer<>(p -> new Anchor(UI.getCurrent().getRouter().getUrl(
            PersonView.class, p.getName()), p.getName()))).setHeader("Name");

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