ember-cli-pagination
ember-cli-pagination copied to clipboard
JSON API compatibility
Now that ember-data final is in the wild and it's default to JSON API, a lot of people are going to be making moves to make their APIs compatible.
I realize that before JSON API, Kaminari was the best option for defaults, but now I think we should switch to JSON API compatible pagination.
We're currently having to do some crazy param mapping stuff every single place we need to do it and we can't even get the total pages to render properly.
Meta Tag Example for Pagination Metadata
{
"meta": {
"page": {
"offset": 1,
"limit": 10,
"total": 35
}
}
}
Request Parameters Examples
page[number]page[size]page[offset]page[limit]page[cursor]
+1 All hail JSON API
+1
+1. Really looking forward to it.
This needs to get done. I'd like to start on it this week.
Thanks @jfelchner for creating the issue. I'll comment with an update when I have one.
:+1:
Would love to see this. Would it make sense to somehow use the links property of the payload rather than whatever might be in meta?
The json api doesn't set any standard for what should be in meta but does enforce standard pagination links. Per the json api specification:
The following keys MUST be used for pagination links:
first: the first page of data
last: the last page of data
prev: the previous page of data
next: the next page of data
which means they are always available versus meta which could be anything. I'm not sure if this is exposed at all by ember data though. Just getting started with it.
@sarus It seems ember-data expects it to be on meta. See: https://github.com/emberjs/data/blob/4e83729f38a158dc9be9aeff667c513ca070e05c/packages/ember-data/lib/serializers/json-serializer.js#L1206
@broerse Not to say that ember data won't make use of the meta field for pagination but I think that function is just a general way to access meta info for any purpose and not necessarily paging (see the guide here http://guides.emberjs.com/v2.1.0/models/handling-metadata/)
I asked on Slack about how Ember Data intends to implement paging and this was the resulting conversation:
sarus [9:18 PM]
Will the ember data "sugar for pagination" use the pagination links `first`, `last`, `prev`, `next` or will it enforce some specific paging parameters set via the `meta` property? I ask because the json-api spec says links must have `first`, `last`, `prev`, `next` pagination links but doesn't enforce any specific usage of the `meta` property. Thanks!
bmac [10:37 PM]
@tchak: ^
NEW MESSAGES
----- Today October 26th, 2015 -----
awesan [5:27 AM]
it says in the spec that those `first`, etc. links MUST be used for pagination
awesan [5:28 AM]
so at the very least it will have to use them, maybe it could use more info from meta tags (edited)
awesan [5:38 AM]
the way I understand the spec it means 'if you do pagination, use these links'
tchak [5:50 AM]
@sarus @awesan the current plan is to add support for pagination links yes
tchak [5:50 AM]
@awesan: the problem with links, is that they do not allow for the case “go to page 3"
munumnun [5:51 AM]
that's where url templates could work :simple_smile:
tchak [5:51 AM]
@munumnun: yes
tchak [5:51 AM]
I was about to say that
tchak [5:51 AM]
but right now there is nothing in the spec about it
tchak [5:52 AM]
would be great to have `n-page` templated link or something
tchak [5:52 AM]
@dgeb ^
munumnun [5:54 AM]
it's kinda bad because you can't use json hal templated links with data right now without doing some nasty hacks
Based on the conversation it seems like the links property will be used but there appears to be some discussion about what else is needed for things like "jump to page" which will either require use of the meta property of templated links.
IMO the API still needs to return both regardless. Parsing "What is the current page?" Out of pagination links is a pain.
@jfelchner @sarus I also think we need both. Now we need something to test against.
any progress made here by anyone in their apps or are people just using some ad hoc solutions where they are shaping the objects that get passed into the PagedRemoteArray
@jfelchner hi, any update on this?
+1 Anyone have a good work around for this?
Frank Treacy has a post about this and shows a good workaround; he even links to this thread. Jump to "#1: Accessing pagination links".
I know this is old, but is there still no solution for pagination in an ember app that adheres to jsonapi-spec?