-
19 Mar 2012 9:10 AM #1
Unanswered: Sorting Nested Data
Unanswered: Sorting Nested Data
My code looks similar to the code below. I'm trying to sort on status, but I haven't been able to figure it out and none of the examples in the documentation show how to do this. I tried store.sort("status", "ASC"), but the nested model fields are ignored.
What is the correct way to sort nested model fields?
Thanks
Code:// JSON returned from the server { "users": [ { "id": 1, "name": "Ed", "orders": [ { "id": 10, "total": 10.76, "status": "invoiced" }, { "id": 11, "total": 13.45, "status": "shipped" } ] } ] } Ext.define('User', { extend: 'Ext.data.Model', config: { fields: [ {name: 'id', type: 'int'}, {name: 'name', type: 'string'} ], hasMany: {model: 'Orders', name: 'orders'} } }); Ext.define('Product', { extend: 'Ext.data.Model', config: { fields: [ {name: 'id', type: 'int'}, {name: 'total', type: 'float'}, {name: 'status', type: 'string'} ] } });
-
19 Mar 2012 10:32 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
TreeStore doesn't really support filtering, that method is inherited from Ext.data.Store. TreeStore has some handleTreeSort and handleTreeInsertionIndex that seems to work with sort
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
19 Mar 2012 10:58 AM #3
A bug was preventing me from sorting on the nested (hasMany) fields. The following now works great.
Thanks
Code:var user = store.getAt(0); user.orders().sort('status', 'ASC');


Reply With Quote