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

Using groupBy with date part #204

Open
gbergamo opened this issue Jun 17, 2016 · 10 comments
Open

Using groupBy with date part #204

gbergamo opened this issue Jun 17, 2016 · 10 comments

Comments

@gbergamo
Copy link

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!

@rafaelss95
Copy link

What's your data structure?

@gbergamo
Copy link
Author

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

@rafaelss95
Copy link

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.

@gbergamo
Copy link
Author

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'"

@codekraft-studio
Copy link

i'm using the same solution but I assume it has performance issues with big lists :(

@karandesai28
Copy link

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.

@codekraft-studio
Copy link

codekraft-studio commented Jun 1, 2017

@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.

@karandesai28
Copy link

@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.

@codekraft-studio
Copy link

@karandesai28 yea sorry I answered in early morning and I was still sleepy, I intended groupBy obviously :)

@karandesai28
Copy link

Well I tried in groupBy, but it didn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants