-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
No way to do complex sorts (like descending alphabetic) #488
Comments
Yes, it would be nice to have an js-like customisable collection.compareTwo(m1,m2) function besides the existing collection.comparator(m) function. |
Bump! In a discussion between @kmalakoff and me this issue emerged again. AFAIK is a long lived querelle between the unelegant ES's While I still prefer While some workaround are possible (if every sorting level is made of strings or numbers simply concat them in order), this still forces the sorting on a different domain. In fact we can think of
@kmalakoff has done some (very) interesting work on defining a @Sidnicious has replaced the current BB implementation with a Ecmascript compatible one. Should we consider instead an hybrid solution that checks for the presence of a I'm waiting for @jashkenas and community feedback, but I personally think this issue deserves some attention. |
Technically you can use whatever sort you want. |
@tbranyen: I would be very concerned about performance of your proposal. The use case that made me find this solution was: I wanted to incrementally resort a model in a list while the user was editing its name (now imagine reset-ing the collection in this case!). Two constraints: 1) the string was localized, 2) I wanted to handle the order of strings like Name1, Name 101, Name02 correctly (splitting the string from the number and correctly combining the sort results). In a related note, I submitted a pull request a while ago for an sortAttribute auto-sort parameter (#625). Very useful for this type of use case. |
Backbone's
|
Awesome! |
Since Backbone uses Underscore-style comparators, some types of sort are not possible — like descending alphabetic.
It's also impossible to for comparators to have complex sort conditions, like “sort alphabetically, but put starred items first”.
Here is a gist that extends Backbone.Collection to use ECMAScript-style comparators, but I’m not sure to suggest for a long-term solution.
The text was updated successfully, but these errors were encountered: