1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Answers
    3
    Vote Rating
    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
    Gainesville, FL
    Posts
    37,327
    Answers
    3540
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    212
    Answers
    3
    Vote Rating
    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');

Thread Participants: 1