Unable to create pagination on dto screen

How to create pagination on dto entity browse screen same like other browse ui screen.

  1. Add simplePagination component and link it to a data loader:

    <simplePagination id="pagination" dataLoader="tasksDl" 
                      itemsPerPageVisible="true" 
                      itemsPerPageItems="10"
                      itemsPerPageDefaultValue="10"/>
    
  2. In loader delegate, get the paging parameters from LoadContext and use them to limit the result list by the current page:

    @Install(to = "tasksDl", target = Target.DATA_LOADER)
    protected List<Task> tasksDlLoadDelegate(LoadContext<Task> loadContext) {
        int firstResult = loadContext.getQuery().getFirstResult();
        int maxResults = loadContext.getQuery().getMaxResults();
        return taskService.loadTasks().stream()
                .skip(firstResult)
                .limit(maxResults)
                .toList();
    }
    

    Of course, it’s better to pass paging parameters to the service which returns the data.

  3. Generate totalCountDelegate for the simplePagination component and return the total number of records from it:

    @Install(to = "pagination", subject = "totalCountDelegate")
    private Integer paginationTotalCountDelegate(final DataLoadContext dataLoadContext) {
        return taskService.loadTasks().size();
    }
    
1 Like