VadimDez / ngx-order-pipe

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

Order does not work for Date #60

Closed ninasleepyhead closed 3 years ago

ninasleepyhead commented 6 years ago

Hi VadimDez,

Thank you so much for this awesome tool.

I am using Angular 5.2.0 and ngx-order-pipe: 2.0.1

The sort does not work for date

My displayed date is like below: {{ testDate | date:'d MMMM yyyy' }}

The real date format in JSON is like this: Tue Mar 20 14:15:23 MDT 2018

Can you please help? Thank you.

mitschmidt commented 6 years ago

I am facing the same issue with Dates not working in the order pipe. That would be a great feature as they are obviously orderable and it seems like a common use case, e.g. for dates in an event list.

Thanks for the module btw - and let me know if you need man power assistance with adding this functionality.

fmonteroponcedeleon commented 6 years ago

Hi VadimDez,

Thanks for your plugin. It's great but I'm also having the same problem when I sort the dates.

I am using Angular: 5.2.2 and ngx-order-pipe: 2.0.1.

My format show is: 'LLL-dd-yyyy')

Could you help us?

Thanks, Francisco

fmonteroponcedeleon commented 6 years ago

Hi everyone,

If you use a string type instead of a date type, the sort works properly!

I hope this will help. Francisco

ninasleepyhead commented 6 years ago

Hi everyone,

Yes, if your original date format is similar like 'yyyy-MM-dd'(put the year in the front), the sort works great. And then you can use Angular date pipe to change to the date format you need.

Hope it helps.

Best, Sleepyhead

chetan-northout commented 5 years ago

HI, i am facing same issue but my date format is | date:'MM/dd/yyyy'

mauriciogracia commented 5 years ago

Another aproach is to use

yourdate.getTime()

to convert the date-time to a timestamp and sort on that propierty that is now a number

langr commented 4 years ago

@mauriciogracia. Your approach helped. Created a new column for formatting yourdate from string to number in the angular app.model.ts, then use the new column in html with order=='new field name'. it worked. hope it is helpful.

mauriciogracia commented 4 years ago

@langr is great to know that it has help you, your explanation will surely help other people with same issue.

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.

VadimDez commented 3 years ago

Dates should be working find since 2.1.0

jcanning commented 3 years ago

@VadimDez

I am still not able to get the orderBy to work with date. I am using 2.1.1

`<tr *ngFor="let booking of activeBookings">

{{booking.start | orderBy:"booking.start":false}}

`

This is what i am doing, pretty simple usage, also tried using moment date format. My date time looks like this "2020-06-20T12:00:00-03:00" or "Nov 11, 2020" when using moment.

I also tried putting my momentDatePipe before the orderBy and after with no difference. I also tried true and false for the second parameter.

Any thoughts?

VadimDez commented 3 years ago

@jcanning seems to be working fine https://stackblitz.com/edit/ngx-order-pipe-jnvcw4

jcanning commented 3 years ago

Hi @VadimDez,

Thanks! At first this still didnt work for me but then I noticed i am actually putting the orderBy on the field not the *ngFor. That was such a silly mistake but it is all working as expected for sorting dates and using moment. This is a great easy to use plugin. Thanks for creating this!