I would like to be able to sort an ArrayController whose contents arise from an ember-data request. Unfortunately, mixing sortProperty doesn't seem to work in this case.
I would like to be able to do the following:
App = Ember.Application.create(); App.store = DS.Store.create({ revision: 4}); App.Item = DS.Model.extend({ id: DS.attr('string'), name: DS.attr('string') }); App.store.createRecord(App.Item, {id: '4', name: 'banana' }); App.store.createRecord(App.Item, {id: '2', name: 'apple'}); App.store.createRecord(App.Item, {id: '6', name: 'spaghetti'}); App.ItemsController = Ember.ArrayController.create({ content: App.store.findAll(App.Item), sortProperties: ['name'] });
With the latest version of Ember and Ember-data, this gives the result:
[ id: 4, name: banana ] [ id: 2, name: apple ] [ id: 6, name: spaghetti ]
The problem here is that App.store.findAll() returns a RecordArray whose content property is not just an array of App.Item instances (in this case, the contents [2, 3, 4])
To access instances, I need to use something like objectAt() . But even if I extract instances of App.Item from RecordArray and dump them in a regular array, everything does not work as expected.
Am I missing an obvious way to do this, or is it just the current state of the framework? I would prefer not to replicate all my models as simple objects in order to sort them.
EDIT:
I had a problem creating my own ArrayController . However, it would be nice if everything was done as described above.
EDIT # 2:
Original steering column template:
<script type="text/x-handlebars"> {{#each App.ItemsController.content }} <p>[ id: {{id}}, name: {{name}} ]</p> {{/each}} </script>
(Also, I used the sortProperty property instead of sortProperties in my code above, but it was just a typo.)
And yes, if used instead
<script type="text/x-handlebars"> {{#each App.ItemsController.arrangedContent }} <p>[ id: {{id}}, name: {{name}} ]</p> {{/each}} </script>
Then we get exactly what we want:
[ id: 2, name: apple ] [ id: 4, name: banana ] [ id: 6, name: spaghetti ]