wintermeyer
wintermeyer

Reputation: 8318

How to use sortProperties: ['lastName']

I'd like to sort an Array or users which gets fetched by ember-data. I can't figure out to sort the array be lastName. The following code doesn't do the job. How can I fix it?

app.js

App.UsersRoute = Ember.Route.extend({
  model: function() {
    return App.User.find();
  }
});

App.UsersController = Ember.ArrayController.extend({
  sortProperties: ['lastName'],
  sortAscending: true
})

index.html

<script type="text/x-handlebars" data-template-name="users">
  <table class='table table-striped'>
      {{#each model itemController="user"}}
        <tr>
          <td>{{lastName}}</td>
        </tr>
      {{/each}}
  </table>
</script>

Upvotes: 3

Views: 2109

Answers (1)

wintermeyer
wintermeyer

Reputation: 8318

Kudos to Bradley Priest for answering the question. Using this in the template does the trick.

index.html

<script type="text/x-handlebars" data-template-name="users">
  <table class='table table-striped'>
      {{#each this itemController="user"}}
        <tr>
          <td>{{lastName}}</td>
        </tr>
      {{/each}}
  </table>
</script>

Upvotes: 8

Related Questions