Skip to content

Instantly share code, notes, and snippets.

@straydogstudio
Last active August 29, 2015 14:10
Show Gist options
  • Save straydogstudio/9d1b6675de621f8f4a76 to your computer and use it in GitHub Desktop.
Save straydogstudio/9d1b6675de621f8f4a76 to your computer and use it in GitHub Desktop.
Ember-CLI-101 sortable issue
import DS from 'ember-data';
export default DS.ActiveModelAdapter.extend({
namespace: 'api/v4',
coalesceFindRequests: true
});
import Ember from 'ember';
export default Ember.ArrayController.extend({
sortAscending: false,
sortBy: 'fullName',
sortProperties: Ember.computed('sortBy', function() {
return [this.get('sortBy')];
}),
actions: {
setSortBy: function(fieldName) {
console.log('setting sort by to '+fieldName);
this.set('sortBy', fieldName);
this.toggleProperty('sortAscending');
return false;
}
}
});
<h1>{{model.length}} Friends</h1>
<table class="primary">
<thead>
<tr>
<th {{action "setSortBy" "fullName"}}>Name</th>
<th {{action "setSortBy" "totalArticles"}}>Articles</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each}}
<tr>
<td>{{link-to fullName 'articles' this}}</td>
<td>{{totalArticles}}</td>
<td><a href="#" {{action "delete" this}}>Delete</a></td>
</tr>
{{/each}}
</tbody>
</table>
import Ember from 'ember';
import DS from 'ember-data';
export default DS.Model.extend({
articles: DS.hasMany('article', {async: true}),
email: DS.attr('string'),
firstName: DS.attr('string'),
lastName: DS.attr('string'),
totalArticles: DS.attr('number'),
twitter: DS.attr('string'),
fullName: Ember.computed('firstName', 'lastName', function() {
return this.get('firstName') + ' ' + this.get('lastName');
})
});
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
sortBy: {
refreshModel: true
},
sortAscending: {
refreshModel: true
}
},
model: function() {
return this.store.find('friend');
},
actions: {
}
});
<h1>{{model.length}} Friends</h1>
<table class="primary">
<thead>
<tr>
<th {{action "setSortBy" "fullName"}}>Name</th>
<th {{action "setSortBy" "totalArticles"}}>Articles</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each friend in model}}
<tr>
<td>{{link-to friend.fullName 'articles' friend}}</td>
<td>{{friend.totalArticles}}</td>
<td><a href="#" {{action "delete" friend}}>Delete</a></td>
</tr>
{{/each}}
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment