VadimDez / ngx-order-pipe

▼ Angular 5+ orderBy pipe
https://vadimdez.github.io/ngx-order-pipe/
MIT License
243 stars 57 forks source link

Incorrectly Sorts Mixed Strings #71

Closed jcmcallister closed 3 years ago

jcmcallister commented 6 years ago

For strings that end in numbers, the sort seems to be incorrect. Consider the following:

Example array of strings: ["host1", "host2", "host20", "host12"] Displays: ["host1", "host12", "host2", "host20"] Expected: ["host1", "host2", "host12", "host20"]

This may be a result of the generalist transform algorithms happening in the Pipe, and may be fixable with the use of an extra comparator function during Pipe setup/consumption in my ngx component.

Figured it would be better to raise this issue overtly, in any case, due to this repo's popularity.

marzoukiniz commented 6 years ago

I still have the same issue , any updates ??

rafa-suagu commented 5 years ago

Same here

anisabboud commented 5 years ago

To use "natural sorting", you can add this comparator (from https://stackoverflow.com/a/38641281) to your typescript file:

comparator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'}).compare;

And then use it in the template (see https://github.com/VadimDez/ngx-order-pipe#usage):

<li *ngFor="let item of array | orderBy: order : false : false : comparator">
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

rafa-suagu commented 3 years ago

@VadimDez some news here?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.