1. #1
    Sencha User
    Join Date
    May 2010
    Posts
    33
    Vote Rating
    0
    Nightwish is on a distinguished road

      0  

    Default [SOLVED] Best practice for attaching listeners to data store (the Ext Designer way)?

    [SOLVED] Best practice for attaching listeners to data store (the Ext Designer way)?


    Pardon my newbie inquiry but how would I structure a descendant of an already-defined JsonStore (via the Ext Designer) so that I can attach some listeners? Is that even the recommended best practice? Or would any and all listeners go in the viewport.js file? Please provide a complete example if possible for those of us who are still learning this new way of doing things.

    Code:
    SDMonthYearStore = Ext.extend(Ext.data.JsonStore, {
        constructor: function(cfg) {
            cfg = cfg || {};
            StormDatMonthYearStore.superclass.constructor.call(this, Ext.apply({
                storeId: 'MonthYearStore',
                root: 'Data',
                idProperty: 'ID',
                totalProperty: 'TotalCount',
                autoSave: false,
                url: '/sd/api.svc/lookup/MonthYearData',
                autoLoad: true,
                restful: false,
                sortField: 'ID',
                sortDir: 'DESC',
    
                // THIS IS A NO-NO SINCE THIS FILE IS AUTO-GENERATED AND OVEWRITTEN EVERY TIME
                listeners: {
                    load: console.log,
                    loadexception: console.log
                },
                
                fields: [
                    {
                        name: 'ID',
                        type: 'string'
                    },
                    {
                        name: 'Text',
                        type: 'string'
                    }
                ]
            }, cfg));
        }
    });
    new SDMonthYearStore();

  2. #2
    Sencha User j-joey's Avatar
    Join Date
    Apr 2008
    Location
    Mersin, Turkey
    Posts
    186
    Vote Rating
    0
    j-joey is on a distinguished road

      0  

    Default


    bind it to a component. use your components store property to access the store directly.

    for instance

    grid.store.on( { 'load' : console.log, 'loadexception' : console.log } );

  3. #3
    Sencha User
    Join Date
    May 2010
    Posts
    33
    Vote Rating
    0
    Nightwish is on a distinguished road

      0  

    Default


    Alright, that makes sense! What about binding several components to the same store - is that a good practice or no?

    Also, thanks for being kind and responding to this and my other question!

  4. #4
    Sencha User j-joey's Avatar
    Join Date
    Apr 2008
    Location
    Mersin, Turkey
    Posts
    186
    Vote Rating
    0
    j-joey is on a distinguished road

      0  

    Default


    nightwish you're welcome...

    there is no restriction how many component you can bind to same store. it maybe useful sometimes but you should remember if you filter a store you'll see your every-component will be filtered. if you reload it same happens. if you bind a paging toolbar, same haapens (actually this is just filtering)... so, if you need independent data you'll need independent stores...

    if you bind a store to more than a component there is no importance how you access the store. when you access to the store you via component's store property, actually you just access to a pointer which points to the store. so you can still user the grid.store.on approach...

    one other way is binding a variable to store's instance. without it, store works because when you assign a storeId to a store it auto-registers itself to storeManager. then components checks their store property if a string value assigned. if so, it just calls a statement like this to access to store.

    var MonthYearStore = Ext.storeMgr.get( 'MonthYearStore' );

    so you can alse use this approach to access store. also you can alter the last line of generated store file to bind a variable to the store's instance.

    var MonthYearStore = New new SDMonthYearStore();

    i hope those info suits your need. see you.

  5. #5
    Sencha User
    Join Date
    May 2010
    Posts
    33
    Vote Rating
    0
    Nightwish is on a distinguished road

      0  

    Default


    Thanks, joey, you are a champ! This was very clear and helpful!

  6. #6
    Sencha - Desktop Packager Dev Team jarrednicholls's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD.
    Posts
    1,745
    Vote Rating
    7
    jarrednicholls will become famous soon enough jarrednicholls will become famous soon enough

      0  

    Default


    Thanks joey.

    One of the great things about stores is that you can bind them to multiple components at the same time. In fact, that's how PagingToolbar works...it and, say, a GridPanel both bind to the same store, thus giving you the paging effect in a GridPanel. But as joey stated, all components bound to a store will obviously see the effects of any filtering, sorting, etc. that happens to the data in the store. Usually if you're binding to more than on component intently, then that behavior is actually what you want. Just need to consider it, that's all.

Similar Threads

  1. Store generated by Ext Designer
    By marcn44 in forum Ext Designer: Help & Discussion
    Replies: 4
    Last Post: 29 Apr 2010, 9:09 AM
  2. how to use mysql data on ext designer?
    By alissonfg in forum Ext Designer: Help & Discussion
    Replies: 5
    Last Post: 3 Apr 2010, 5:52 AM
  3. Replies: 1
    Last Post: 31 Mar 2010, 9:34 AM
  4. Ext 2.2.1 best practice of using radiogroup listeners.
    By rob1308 in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 19 Feb 2010, 11:29 AM
  5. How many listeners on Ext.data.Store?
    By deitch in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 6 Nov 2007, 9:58 AM

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar