mherBaghinyan
mherBaghinyan

Reputation: 476

spring data paging with start and end counts

I'm using spring data with mongodb and have issue which is described below.

Pageable pageRequest = new PageRequest(page, count);
return projectRepository.findAllByUserId(userId, pageRequest);

from the frontend part i'm getting start and end values for returning a page result but unfortunately i can't get the page number because i use scrollable loading not a pager. and seems spring data allows only make a pageRequest with these 2 parameters, page number and data count.

Is there a way to pass only start and end of the data and return a page result instead with spring data?

Upvotes: 2

Views: 1590

Answers (2)

BitfulByte
BitfulByte

Reputation: 4456

Assuming you have the same size each time you can calculate the page numbers as start / size. Example: start: 70, size: 10, page = (70/10) 7 But it is 0-based by default, so your actual page number is 6

Upvotes: 0

Ritesh Gupta
Ritesh Gupta

Reputation: 76

Every time you scroll you might be fetching a fixed number of records? Each scroll event should help you track the page numbe, and the count can be the number of records you pull afresh.

Hope that helps.

Upvotes: 0

Related Questions