Using groupBy with date part
Hi.. I cannot find a way to group by my array with a date part (dd/MM/yyyy). I have to group by day/month/year of a date property, how can I do it?
thanks!
What's your data structure?
Messages = [ { id: 1, sent: Date(), message: "" }, { id: 1, sent: Date(), message: "" } ]
It's something like that... 'Sent' is timespam I want to group messages by MM/dd/yyyy
Thanks
Well, I had a problem with groupBy with dates because my dates were formatted as timestamp, so I changed the format to MM/dd/yyyy before render the view, then it worked. You can format them both server-side as client-side.
To resolve that I use map function to before groupBy, so, on map function I create a new formatted property (MM/dd/yyyy). It works, but I don't know if that is the better way to do that. (honestly, I didn't like the solution)
ng-repeat="(key, value) in mensagens | map: dateFormatter | groupBy: 'dateFormatted'"
i'm using the same solution but I assume it has performance issues with big lists :(
Above solution proposed by @rafaelss95 can work if I want to group by date. But I have a requirement to group by Date as well as time (complete timestamp), and in such cases groupBy is misbehaving. It would be great if someone would investigate the issue.
@karandesai28 try to change the date format to something (for example) like mysql datetime: YYYY-MM-DD HH:MM:SS so the ~orderBy~ groupBy compare function will compare the full timestamp instead to compare only the date, I guess.
@codekraft-studio Thanks for reply. Just to confirm, I mentioned about groupBy, not orderBy. Will it work for groupBy? I'll try from my end though.
@karandesai28 yea sorry I answered in early morning and I was still sleepy, I intended groupBy obviously :)
Well I tried in groupBy, but it didn't work