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

Multiple orders with date, second item is reversed #91

Closed
bluecaret opened this issue Oct 9, 2019 · 2 comments · Fixed by #103
Closed

Multiple orders with date, second item is reversed #91

bluecaret opened this issue Oct 9, 2019 · 2 comments · Fixed by #103

Comments

@bluecaret
Copy link

I have a strange issue that is causing my second column that needs to be sorted to be sorted in reverse order from the first.

Stackblitz: https://stackblitz.com/edit/ngx-order-pipe-njfy7p

In the example above it is sorted by DOB and then by Name. But the name column is in reverse order even though both should be ascending. If I sort by multiple columns with anything other than a date it seems to work fine.

Angular v7
ngx-order-pipe v2.0.4

VadimDez added a commit that referenced this issue Oct 16, 2019
@VadimDez
Copy link
Owner

The problem is that:

new Date(1978, 10, 12, 0, 0, 0, 0) == new Date(1978, 10, 12, 0, 0, 0, 0)

Will return false.
Probably the solution would be to extend comparison functions and use Date's getTime() before comparing two Dates.

For now (before actual fix) you could pass your own comparator that handles Dates https://github.com/VadimDez/ngx-order-pipe#arguments
For example;

(a, b) => {
    if (a instanceof Date) {
        a = a.getTime();
        b = b.getTime();
    }
    if (a === b) {
      return 0;
    }
    if (a == null) {
      return 1;
    }
    if (b == null) {
      return -1;
    }
    return a > b ? 1 : -1;
}

@stale
Copy link

stale bot commented Jul 31, 2020

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.

@stale stale bot added the stale label Jul 31, 2020
@VadimDez VadimDez added this to the 2.1.0 milestone Aug 10, 2020
VadimDez added a commit that referenced this issue Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants