I'm writing a simple sort / pagination controller using ember pre 1.0. I want to change the sort property on the controller when the user clicks a column header on the table. I have a simple action helper that points to my routers sortUser method but I can't seem to pass in a raw string that the route can use as the param such as "username" or "id"
Also my url seems broken (getting this url)
http://localhost:8000/#/sort/undefined
instead of
http://localhost:8000/#/sort/username
Thank you in advance
<table width="250px">
<thead>
<th><a {{action sortUsers "id" href=true}}>id</th>
<th><a {{action sortUsers "username" href=true}}>username</th>
<th>update</th>
<th>delete</th>
</thead>
<tbody>
Here is my router (cutting out some complexity but it is a nested route)
PersonApp.Router = Ember.Router.create({
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/',
paginateUsers: Ember.Route.transitionTo('paginated'),
sortUsers: Ember.Route.transitionTo('index.sort.index'),
connectOutlets: function(router, context) {
router.get('applicationController').connectOutlet('person', router.get('store').findAll(PersonApp.Person));
},
index: Ember.Route.extend({
route: '/'
}),
paginated: Ember.Route.extend({
route: '/page/:page_id',
connectOutlets: function(router, context) {
router.get('personController').set('selectedPage', context.page_id);
},
exit: function(router) {
router.get('personController').set('selectedPage', undefined);
}
}),
sort: Ember.Route.extend({
route: '/sort/:column',
serialize: function(router, context) {
if (context) { return { sort: context.sort } }
return {sort: undefined}
},
deserialize: function(router, context) {
return { sort: context.column }
},
connectOutlets: function(router, context) {
router.set('personController.sortProperties', ['username']);
router.get('personController').set('selectedPage', 1);
},
UPDATE
I have a full jsfiddle of this in action now (the sorting along side filter + pagination)