Pagination in Grid

Hi everybody,

I am thinking a way to combine data provider of grid and pagination together. After looking around forum, I’m still not found any answer than using addon. The reason i don’t want to use addon because I want to customize my own UI, how its look.

The current data provider have good lazy loading functional, but assume I’m having 1000 data, and I will get it through REST API. So I created a grid with 20 data/page, everytime i change my page to next page, the data provider would like to request to API to get next 20 data then show to vaadin grid.

But now, I am still out of idea how to implement that idea. If anyone implemented this feature, please guide me.

Thank you.
Have a nice day.


here’s a very simple prototype:

public class GridView extends HorizontalLayout {

    private int totalAmountOfPages;
    private int itemsPerPage = 10;
    private int currentPageNumber = 1;

    public GridView() { ;
        Grid<Bean> grid = new Grid<>(Bean.class);
        totalAmountOfPages = RestApi.getPageCount(itemsPerPage);
        List<Bean> initialItems = RestApi.getPageItems(currentPageNumber, totalAmountOfPages, itemsPerPage);
        Button nextButton = new Button("Next page", e -> {
            if (currentPageNumber >= totalAmountOfPages) {
            List<Bean> nextPageItems = RestApi.getPageItems(++currentPageNumber, totalAmountOfPages, itemsPerPage);
        Button previousButton = new Button("Previous page", e -> {
            if (currentPageNumber <= 1) {
            List<Bean> prevPageItems = RestApi.getPageItems(--currentPageNumber, totalAmountOfPages, itemsPerPage);
        add(grid, previousButton, nextButton);

To elaborate on the example a bit: if you’re using pages, there’s no reason to use a lazy loading DataProvider at the same time. Just load the items of the current page into memory and put them into the Grid. Keep track of the current page number, items per page and the amount of pages yourself and you’re left with free hands to implement the UI part yourself as you wish.


Starting from V17 the Grid supports API for data lazy loading from paged repositories:

grid.setItems(query -> service.fetchPage(query.getPage(), query.getPageSize()));

More information here

Hope this helps.