Skip to content

Instantly share code, notes, and snippets.

@yusufsyaifudin
Created October 31, 2019 05:05
Show Gist options
  • Save yusufsyaifudin/9c84f43c5654113185a8f896cec69234 to your computer and use it in GitHub Desktop.
Save yusufsyaifudin/9c84f43c5654113185a8f896cec69234 to your computer and use it in GitHub Desktop.
Pagination
parameter from request = page and limit
so,
offset = (page - 1) * limit
but you need to check if page <= 0 then page = 1
if limit <= 0 then set it to default minimum limit
If your request is only limit and offset, then you need to calculate the current page:
page = (limit + offset) / limit
but you need to check if offset < 0 then default to 0, and limit is must set to default minimum limit, let say = 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment