Grid Callback Data Provider wrong query parameter values

Hello!

I have a problem with implementation of lazy-loading for Grid. The following code represent DataProvider:

private DataProvider<ReservationDTO, Void> buildDataProvider() {
    return DataProvider.fromCallbacks(
        query -> {
            final List<SortDTO.OrderDTO> orders = query.getSortOrders().stream()
                .map(queryOrder -> SortDTO.OrderDTO.builder()
                    .property(queryOrder.getSorted())
                    .direction(queryOrder.getDirection() == SortDirection.DESCENDING ? DirectionEnum.ASC : DirectionEnum.DESC)
                    .build()
                )
                .collect(Collectors.toList());

            if (orders.isEmpty()) {
                orders.add(SortDTO.OrderDTO.builder()
                    .property("createdAt")
                    .direction(DirectionEnum.ASC)
                    .build());
            }

            final FindReservationsRequestDTO request = FindReservationsRequestDTO.builder()
                .criteria(buildSearchCriteria())
                .sort(SortDTO.builder()
                    .orders(orders)
                    .build())
                .build();

            return reservationsResource.getAllReservations(request, query.getOffset(), query.getLimit()).getContent().stream();
        },
        query -> reservationsResource.getReservationCount(FindReservationsRequestDTO.builder()
            .criteria(buildSearchCriteria())
            .build())
    );
}

If i understand it right, “offset” and “limit” values of query have to be defined automatically by Vaadin. But when i debug peace of code above i can see that offset = 0, limit = 2147483647. It means that all data from database is loaded by first and only one query. So, lazy-loading in this case doesn’t make any sense.

Please help to understand what i did wrong!

I’m having a slightly similar issue, and I would like to know how Vaadin calculates the offset and limit too.

Hi,

The offset and limit in the query that goes to the “size” method does indeed have
offset = 0, limit = Integer.MAX_VALUE
. The one going to the actual row fetching should contain initially from 0 to 40, unless you want a different initial row count (see:
grid.getDataCommunicator().setMinPushSize()
). If you do get the “full length” query in your data provider initially, then somewhere something is broken and needs to be fixed.

//Teemu

Hi,

please find the code below
grid.getDataCommunicator().setMinPushSize(40);
grid.setDataProvider((sortOrder,limit,offset)->userService.getUserList(offset,limit).stream()
,()->userService.getUserListCount());

------In UserService.java----
public List getUserList(int offset,int limit){
//your code
criteria.setFirstResult(offset);
criteria.setMaxResult(end);
return criteria.list();
}