Open MichaelMarner opened 8 years ago
attr('date')
converts your string to a Date Object and new Date('2015-09-29') !== new Date('2015-09-29');
. Use a string representation of the date to group on.
Yeah that's what I'm doing. I guess I thought it would work out of the box with all Ember attribute types. However that would require code to specifically handle Date objects, so I understand if you don't want a special case to handle them.
FWIW bumped into the same issue and fixed using a computed property to convert the date to string. However, it would be really handy if this case was handled out of the box. Alternatively, have you considered using a custom group by function instead of a key? Like having group
/ groupBy
to mimic Ember's find
/ findBy
?
Hi guys, I have noticed the same problem with grouping by date. I have a question for @basicNew. Can you show me with an example how did you make a computed property to convert the date to string?
@jelhan TY buddy. I have implemented it. This is my code inside Ember's app/models/model.js
propertyToString: Ember.computed('originalDateProperty', function(){
return `${this.get('originalDateProperty').toDateString()}`
})
groupBy does not work if you are trying to group using Ember's date attribute. Suppose we have a model:
And we get data from a JSON endpoint that looks like this:
We have a controller that uses groupBy to group them by the date attribute:
Which we then use in a template:
We would expect the output to be:
However, groupBy puts each of the entries into their own group. Changing the attr in the model from
date
tostring
gives the expected output.