Skip to content

groupBy doesn't work with date properties #11

@MichaelMarner

Description

@MichaelMarner

groupBy does not work if you are trying to group using Ember's date attribute. Suppose we have a model:

// app/models/entry.js
export default Model.extend({
  name: attr('string'),
  date: attr('date'),
});

And we get data from a JSON endpoint that looks like this:

[
        {
            "name": "Object 1",
            "date": "2015-09-29",
        },
        {
            "name": "Object 2",
            "date": "2015-09-30",
        },
        {
            "name": "Object 3",
            "date": "2015-09-30",
        },
]

We have a controller that uses groupBy to group them by the date attribute:

// app/controllers/view.js
import Ember from 'ember';
import groupBy from 'ember-group-by';

export default Ember.Controller.extend({
   entriesByDate: groupBy('model', 'date')
});

Which we then use in a template:

{{#each entriesByDate as |group| }}
  <h1>{{group.value}}</h1>
  {{#each group.items as |entry| }}
    {{entry.name}}<br>
  {{/each}
{{/each}

We would expect the output to be:

<h1>2015-09-29</h1>
Object 1<br>
<h1>2015-09-30</h1>
Object 2<br>
Object 3<br>

However, groupBy puts each of the entries into their own group. Changing the attr in the model from date to string gives the expected output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions