What is the logic to display "You reached the end.. No more items available"


#1

I am requesting data from a web service with page number & limit. For example, I start with page number 1 & limit as 10. Each time when I request, I increment the page number with the same limit. The limit can be set to anything… Here, the client decides the size of the page & number of pages. Is this the right approach?
When the requested page is not available, the service returns the last page.

Should the server be the one who decides the page size & number of pages? Need suggestions @leob

And also how to display “You reached the end… No more items available”. Whether the service should return me the status “You reached the end” or the client has to determine it by comparing it with previous response?

My doubt is "Who has to be the master for pagination? Service or client? "


#2

I have no experience with this in the context of an Ionic application, but the right approach seems to be if the client just sends a page number and page size to the server, and then the server figures out which rows of the data set to send to the client and then sends ONLY those rows.

And it’s also the server who would be able to calculate the number of available pages, based on the page size that it gets from the client (the client can do a REST call to ask the server how many pages there are).

If all of the pagination logic is in the client then the server has to send the COMPLETE dataset (all of the rows) to the client, which could mean sending thousands (or more) rows over the network and putting them all in the client’s memory. This is of course very inefficient,

So it’s fairly obvious what the right approach is: it’s the client that makes the requests and determines what the page size should be, but all the calculations and retrieving the right rows are left to the server. All the client does is ask “how many pages are available, if the page size is X” and “give me the rows for page Y, if the page size is X”.


#3

@leob, I arrived at the solution. The client requests the service with page number & size. The web service then determines if TotalNoOfItems - (PageNumber * PageSize) < 0. Which means that “No more items”!
Thanks for spending time :smile:


#4

Yup that is in fact what I meant … :wink: