1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
    Answers
    3
    bweiler is on a distinguished road

      0  

    Default 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'}
            ]
        }
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,599
    Vote Rating
    434
    Answers
    3102
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Vote Rating
    3
    Answers
    3
    bweiler is on a distinguished road

      0  

    Default


    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');