Kurounin / Pagination

This package allows you to paginate the subscriptions over meteor's collections. It can be used in a Blaze template or in ReactJS.
MIT License
56 stars 22 forks source link

Custom sort on pagination #90

Closed ThomasAtome closed 5 years ago

ThomasAtome commented 5 years ago

Hi, i need to sort all my collection with a custom sort function like i see here : https://stackoverflow.com/questions/35141284/custom-sort-for-a-mongodb-collection-in-meteor

How can i do this ? I try but there is no effect

Thanks

Kurounin commented 5 years ago

Hi,

What kind of custom sorting are you trying to use? The transform option method mentioned in that answer is not suitable for pagination as it is applied only to retrieved documents, which would mean that on server side all the collection documents should be kept in memory to be able to apply the transform function on them, before paginating them and sending only the needed ones to the client.

ThomasAtome commented 5 years ago

Hi, i have a collection with for exemple this documents : { _id: 1, value: "foo foo", _id: 2, value: "foo bar", _id: 3, value: "bar bar", _id: 4, value: "foo foo", _id: 5, value: "foo bar", _id: 6, value: "bar bar" }

In my collections i have 1 000documents. I want to sort them with a certain order like all "foo foo" first, then all "foo bar" and all other after.

How can i achieve this ?

Thanks :)

Kurounin commented 5 years ago

Why not add some additional properties, that you can use to sort after?

{ _id: 1, value: "foo foo", sortPrimary: 1}
{ _id: 2, value: "foo bar", sortPrimary: 2}
{ _id: 3, value: "bar bar", sortPrimary: 3}
{ _id: 4, value: "foo foo", sortPrimary: 1}
{ _id: 5, value: "foo bar", sortPrimary: 2}
{ _id: 6, value: "bar foo bar", sortPrimary: 3}
{ _id: 6, value: "foo bar bar", sortPrimary: 3}

So you could sort using {sortPrimary: 1, value: 1}