Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor based pagination #39

Closed
JeanLucEsser opened this issue Feb 17, 2017 · 2 comments
Closed

Cursor based pagination #39

JeanLucEsser opened this issue Feb 17, 2017 · 2 comments

Comments

@JeanLucEsser
Copy link
Contributor

I didn't find anything on a cursor based pagination which is allowed by the spec. This sort of pagination is very useful and common in an API, specially if coupled with an index of sort (alphabetical mostly):

  "meta": {
    "page": {
      "size": 20,
      "cursor": 0,
      "total": 10000,
      "index": {
        "A": 0,
        "B": 227,
        "C": 1136,
        ...
        "X": null,
        "Y": 9837,
        "Z": 9884,
        "#": null
      }
    }
  },
  "links": {
    "prev": null,
    "next": "http://jsonapi.dev/api/v1/people?page[cursor]=20&page[size]=20"
  },

How would you go about implementing this?
For now, I don't see another way than bypassing your pagination and using the filter method on the Search class to 1/ manually paginate via skip/take and 2/ clone the builder to create the alphabetical index. But then I don't see how to manually create the meta and links objects and pass them to the returned Json.

Any help would be much appreciated.

@lindyhopchris
Copy link
Member

Hi! Your solution of using the filter method is the best approach at the moment. We're planning a lot of upgrades to the search solution, including the pagination. Out-of-the box pagination support will only ever exist for the pagination strategy implemented by Laravel, which is page based. But we're hoping to make it a lot easier to tie in pagination for specific resource types that need their own pagination approach, e.g. cursor based as you need.

Any suggestions as to how you'd like to integrate cursor based pagination would be appreciated.

I'll leave this issue open as it is related to our plans to upgrade the search functionality.

@lindyhopchris
Copy link
Member

The latest version v0.8 allows for a paging strategy to be injected into the EloquentAdapter class (this was previously EloquentSearch).

This means you can implement cursor based pagination by writing a class that implements Contracts\Pagination\PagingStrategyInterface and then inject that into any adapters that need to use that paging strategy.

Any questions let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants