-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(orderBy): Support natural sort #12572
Comments
This is one of those things and always found a reasonable workaround (eg |
Maybe a new filter that converts to integer before ordering? orderByInt() |
@Narretz I'd like to know your oppinion about this feature, I could create a new filter. |
I've definitely run into this problem before, where I have a field that I want to order by in an ng-repeat, and the field is a number but for a variety of reasons is stored in js as a string. I've fixed the problem by writing a custom filter that converts to int before comparing using parseInt(num, 2), but would be nice if there was already a filter that did this. |
Is it just me or does this sound like a better fit for an external module (rather than a core feature) ? |
With this change the 3rd argument is interpreted as a comparator function, used to compare the values returned by the predicates. Leaving it empty falls back to the default comparator and a value of `false` is a special case that also falls back to the default comparator but reverses the order. Thus the new implementation is backwards compatible. Helps with angular#12572 (maybe this is as close as we want to get). Fixes angular#13238 Fixes angular#14455 Closes angular#5123 Closes angular#8112 Closes angular#10368
With this change the 3rd argument is interpreted as a comparator function, used to compare the values returned by the predicates. Leaving it empty falls back to the default comparator and a value of `false` is a special case that also falls back to the default comparator but reverses the order. Thus the new implementation is backwards compatible. This commit also xpands the documentation to cover the algorithm used to sort elements and adds a few more unit and e2e tests (unrelated to the change). Helps with angular#12572 (maybe this is as close as we want to get). Fixes angular#13238 Fixes angular#14455 Closes angular#5123 Closes angular#8112 Closes angular#10368
With this change the 3rd argument is interpreted as a comparator function, used to compare the values returned by the predicates. Leaving it empty falls back to the default comparator and a value of `false` is a special case that also falls back to the default comparator but reverses the order. Thus the new implementation is backwards compatible. This commit also expands the documentation to cover the algorithm used to sort elements and adds a few more unit and e2e tests (unrelated to the change). Helps with angular#12572 (maybe this is as close as we want to get). Fixes angular#13238 Fixes angular#14455 Closes angular#5123 Closes angular#8112 Closes angular#10368
Add an optional, 4th argument (`comparator`) for specifying a custom comparator function, used to compare the values returned by the predicates. Omitting the argument, falls back to the default, built-in comparator. The 3rd argument (`reverse`) can still be used for controlling the sorting order (i.e. ascending/descending). Additionally, the documentation has been expanded to cover the algorithm used by the built-in comparator and a few more unit and e2e tests (unrelated to the change) have been added. Helps with #12572 (maybe this is as close as we want to get). Fixes #13238 Fixes #14455 Closes #5123 Closes #8112 Closes #10368 Closes #14468
Add an optional, 4th argument (`comparator`) for specifying a custom comparator function, used to compare the values returned by the predicates. Omitting the argument, falls back to the default, built-in comparator. The 3rd argument (`reverse`) can still be used for controlling the sorting order (i.e. ascending/descending). Additionally, the documentation has been expanded to cover the algorithm used by the built-in comparator and a few more unit and e2e tests (unrelated to the change) have been added. Helps with #12572 (maybe this is as close as we want to get). Fixes #13238 Fixes #14455 Closes #5123 Closes #8112 Closes #10368 Closes #14468
Now that #14468 has landed in master, it will be even easier to do this by providing a custom comparator function. I'm going to close this for now, since it seems like a better fit for an external module. |
This is a feature request. I searched issues and pull request and didn't find anything, sorry if this is a dupe.
I think that many of us would like to be able to ask
orderBy
to sort strings in a "natural" way (i.e.foo 92
"is smaller than"foo 147
, as opposed to the current lexicographical order which sorts1
before9
).I'd be willing to submit a pull request but first I'd like to know if this is a feature the Angular team would like to add, discuss the possible syntax, and get some guidelines (I took a look at
orderByFilter
and noticed it's really optimized for performance).Thanks!
The text was updated successfully, but these errors were encountered: