1. #1
    Sencha User
    Join Date
    Jul 2011
    Location
    Melbourne Australia
    Posts
    8
    Vote Rating
    0
    tdack is on a distinguished road

      0  

    Default [SOLVED] Sorting associated store data

    [SOLVED] Sorting associated store data


    I have a store that has an associated store loaded automatically through the model association.

    How can I have the associated child store of each parent record automatically sorted on a field in the child store?

    Parent Store:
    Code:
    Ext.define('MythTouch.store.ProgramGuide', {
        extend: 'Ext.data.Store',
        requires: [
            'MythTouch.model.ChannelModel'
        ],
    
    
        config: {
            autoLoad: true,
            groupDir: 'ASC',
            groupField: 'ChanId',
            model: 'MythTouch.model.ChannelModel',
            storeId: 'ProgramGuide',
            proxy: {
                type: 'ajax',
                enablePagingParams: false,
                url: 'xml-proxy.php?Guide/GetProgramGuide',
                reader: {
                    type: 'json',
                    idProperty: 'ChanId',
                    rootProperty: 'ProgramGuide.Channels',
                    totalProperty: 'Count'
                }
            }
        }
    });
    Parent Model:
    Code:
    Ext.define('MythTouch.model.ChannelModel', {
        extend: 'Ext.data.Model',
        requires: [
            'MythTouch.model.ProgramModel'
        ],
        config: {
            fields: [
                { name: 'ChanId',     sortType: 'asInt',   type: 'int'  },
                { name: 'ChanNum', sortType: 'asText', type: 'int' },
                { name: 'CallSign' },
                { convert: function(v, rec) {
                        v = "img-proxy.php?" + v.replace("?", "&");
                        return v;  },
                    name: 'IconURL', type: 'string' },
                { name: 'ChannelName' }
            ],
            hasMany: {
                associationKey: 'Programs',
                model: 'MythTouch.model.ProgramModel',
                autoLoad: true,
                name: 'Programs',
                associatedName: 'Programs'
            }
        }
    });
    Associated Child Model:
    Code:
    Ext.define('MythTouch.model.ProgramModel', {
        extend: 'Ext.data.Model',
        requires: [
            'MythTouch.model.RecordingModel'
        ],
        config: {
            fields: [
                { name: 'StartTime' },
                { name: 'EndTime' },
                { name: 'Title' },
                { name: 'Repeat' }
            ]
        }
    });
    Ideally I'd like the store for the associated child model to be sorted on StartTime automatically.

    Creating this in Sencha Architect I can't work out how to make this happen.

    Any advice appreciated.


    Solved!

    Well that turned our easier than expected.

    I simply defined a listener and handler for the refresh event like so:

    Code:
            listeners: [
                {
                    fn: 'onJsonstoreRefresh',
                    event: 'refresh'
                }]
    
    
    // .....
    
    
        onJsonstoreRefresh: function(store, data, eOpts) {
                          store.each(function (record) {
                         record.ProgramsStore.sort('StartTime', 'ASC');
            });
    
    
        }
    Last edited by tdack; 14 May 2012 at 9:29 PM. Reason: [SOLVED]

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    828
    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


    Thank you for posting your solution! That helps others a lot
    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.

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi