My Ember apps use sparse arrays to load visible data on demand. The sparse array needs some means for determining the total number of objects available to show. This allows my colleagues and I to fake the array length property with record counts provided by the server and, for example, draw an appropriately tall scrolling <div> to mimic the appearance of a single, continuous listing.
JSON API spec suggests using the top-level links object to include URLs for the first, last, next, and previous available pages. But offers no suggestions for where to provide a document count. My instinct suggests sending this data in the meta object. After all, the record count is not necessarily useful for every app or api.
I am guessing JR first needs to support the meta object (see #89) before addressing this need. I am opening this issue for future discussion since it is something critical to the apps I work on.
:+1: on this. It would also be useful to have it optional, with the ability to enable it globally or on only specific resources.
This would be useful in some scenarios, like showing the total posts a user has created, and at the same time being able to disable it (avoiding the .count query) for showing for example the number of notification a user has received
@xdmx Agreed! In the extreme case, a Twitter-like app, the total count of tweets in your feed could easily be massively large and essentially useless.
In contrast, a listing of followers may be a large but manageable number that requires a pagination strategy that includes a count of matching records.
:+1: from me too. I don't see a place in the JSON API spec for a total count (right?), but at least supporting the pagination entries in the top-level "links" would be nice.
:+1: on this as well.
The JSON API spec details this use case in the extension specification – take a look at the example in the “Profiles” section.
It belongs indeed to the meta member as @realityendshere was guessing.
:+1: for meta/ pagination!
:+1: Another vote for this! Also using Ember.
+1
it will be better to have choice: add total_count to top level links or meta or even both
The 0.4.0 release now has support for collecting meta data during the processing of the operations, collecting the meta from all operations, and outputting the collected meta as part of the new ResponseDocument.
We chose to forgo adding a standardized option to collect and output total record count since it's not entirely clear as to what the preferred format is, or even if there will be a standard format. Instead the Readme now contains the steps on how to set this up. It's a bit more work, but much more flexible. In the future we can look at adding a configuration option to do this automatically.
The plan is collect top level links in a similar manner, though those will also involve the paginators.
@lgebhardt Can you point me at the docs you mention? I'm trying to add the details below for ember to a controller.
meta: {
page:
per_page:
total:
pages:
}
I find this but I wasn't sure if there was a more specific example for use with Ember.
Disregard I'm all set. For anyone else that ends up here, add this to your jsonapi-resource config.
config.top_level_meta_include_page_count = true
config.top_level_meta_page_count_key = :page_count
Most helpful comment
Disregard I'm all set. For anyone else that ends up here, add this to your jsonapi-resource config.