BabDev / Pagerfanta

Pagination library for PHP applications with support for several data providers
Other
384 stars 170 forks source link

Cursor and offset based paginators #30

Open IonBazan opened 3 years ago

IonBazan commented 3 years ago

Just a few things to consider for v4: Sometimes there is a need to provide an offset-limit pagination instead of human readable "page numbers". This might be useful for API endpoints. Most of the time the offset would match the ($page-1)*$perPage but there might be situations where someone requests offset: 50, limit: 100. A new Adapter (sub)interface could be introduced to address that. Another idea would be to allow cursor-based navigation, where page ID is a cursor. An example would be Shopify API or AWS Cognito API.

stof commented 2 years ago

The adapter interface actually already implements offset+limit rather than page-based pagination. The handling of pages is handled by the Pagerfanta object. To use a generic offset-based pagination, call $adapter->getSlice() directly.

For cursor-based pagination, I don't think this can be implemented as a generic pagination library, as I don't see how to write a generic logic turning the cursor into a filtering condition on the data source.