Search code examples
javavaadinvaadin8

Get List<items> from Vaadin 8 Grid


Problem: I have a Vaadin 8 Grid , and I can't find a way to extract the items inside of it.

Description: Starting from a grid

Grid<Pojo> myGrid = new Grid<>();

I've configured it so it can take data with lazy loading.

    myGrid.setDataProvider(
            (sortOrd, offset, limit) -> dao.getAllFiltered(offset, limit, filter),
            () -> dao.getCountAllFiltered(filter)
    );

At this point, I want to extraxt all the items from the grid (for putting that into an excel), something like List<Pojo> list = myGrid.getItems();. I've also tried passing through myGrid.getDataProvider() , but there are no useful getter into it.

I can't find any getter, how can I achieve this? Thanks


Solution

  • Have you tried this basically?

    List<Pojo> list = grid.getDataProvider()
                          .fetch(new Query<>())
                          .collect(Collectors.toList());