How to create pagination on dto entity browse screen same like other browse ui screen.
-
Add
simplePagination
component and link it to a data loader:<simplePagination id="pagination" dataLoader="tasksDl" itemsPerPageVisible="true" itemsPerPageItems="10" itemsPerPageDefaultValue="10"/>
-
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.
-
Generate
totalCountDelegate
for thesimplePagination
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