0
votes

I have question, what should I do to make sorting working in Ember app? I created simple blog app via ember-cli

Model:

export default DS.Model.extend({
    title: DS.attr('string'),
    publishedAt: DS.attr('date'),
    description: DS.attr('string'),
    body: DS.attr('string')
});

Route structure is:

this.resource('blog', function() {
        this.route('new');
        ...
 });

And in blog/index I have {{#each blog in model}} looping for all data

I added controller blog/index

import Ember from 'ember';

export default Ember.ArrayController.extend({
    sortAscending: true,
    sortProperties: ['date']
});

And nothing seems to work..

2

2 Answers

2
votes

The previous answer is correct, but I personally prefer to collapse this into a single line:

sortProperties: ['publishedAt:desc']

The nice thing about this approach is that you can add additional sorts to the array without worrying about ascending/descending setting at the Controller level.

0
votes

youre sorting by a property that doesnt exist on the model sortProperties: ['date']
You need to sort by a model property:

sortAscending: false,    
sortProperties: ['publishedAt']