craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 57 forks source link

Paginate with offset #99

Closed missmatsuko closed 5 years ago

missmatsuko commented 5 years ago

Is it possible to paginate a query with offset? https://craftcms.stackexchange.com/questions/19924/how-to-skip-the-first-x-entries-using-elementapi

My use case is that I'm adding items to a page. The page loads with 4 items (1 row of 1, 1 row of 3) then paginates with 6 items (2 rows of 3) so I can't just paginate and start from the second page.

I found that offset works if paginate is set to false, but then it's trickier to figure out if I've reached the end of results.

I have figured out that I can still use pagination if I exclude IDs in criteria, so currently I'm thinking to pass the IDs of the first 4 items into my endpoint and exclude those.

brandonkelly commented 5 years ago

We just released Element API 2.6.0 with added support for the offset criteria param:

'criteria' => [
    'offset' => 4,
    // ...
],

With that in place, the first 4 items would never be included in the results.