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

Bug: The package sorts all incoming data by "id" automatically. #54

Closed
leetharris opened this issue Mar 14, 2018 · 3 comments
Closed

Bug: The package sorts all incoming data by "id" automatically. #54

leetharris opened this issue Mar 14, 2018 · 3 comments

Comments

@leetharris
Copy link

As the title states, this package sorts all incoming data by "id" and does not preserve the original order.

This is a problem as we have specific ordering coming out of our backend based on remote "sort" parameters (supported by the JSON-API spec).

@pablorsk
Copy link
Member

pablorsk commented May 4, 2018

Library works with collections. Every element on collection has the resource id as key.

Javascript sort collections by key. On my mind, we have only solution: replace collections for arrays. This solution is very aggressive, because we need change a lot of features. Collections are very fast, because we save cache on memory and browser index db; we need only ask if element exists. If we migrate to array, we need on every interaction traverse all data (imagine relations on each resource of a collection).

Another better idea?

@leetharris
Copy link
Author

We actually made our own workaround for this which may give you some inspiration on how you could handle it in your package.

We created a middleware that checked all incoming arrays and assigned an array_order attribute to each item in the collection.

Then we sorted our tables by this array_order attribute on each resource. Worked out pretty well!

Thanks for making this package!

@OpticNectar
Copy link

@leetharris Could you share your code on this? @pablorsk The order should be based on the server or there should be a sort option. Automatically sorting by ID defeats the purpose of what a lot of this package does, especially since jsonapi itself supports sorting.

pablorsk added a commit that referenced this issue Aug 12, 2018
pablorsk added a commit that referenced this issue Aug 12, 2018
Version 1.1.0 🎆 

* Feature: collections has `data` member now. `data` is an array, and the requested information is kept in order.  Closes #84. Closes #54.
* Feature: trackBy added on collection. Optimize use of ngFor.
* Deprecated: callback functions deprecated on get(), all(), detele() and save().

And...

* Demo: demo-collection-info component added. Show info about received collection.
* tslint: array<> to [] on types
* version 1.1.0 bump
* Readme updated: sort and trackby added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants