Results 1 to 4 of 4

Thread: Store add listener

  1. #1
    Ext User
    Join Date
    Jul 2009
    Posts
    75
    Vote Rating
    1
      0  

    Default Store add listener

    Hi

    I'm trying to update records in a store once they've been added to the store. I've put code in an "add" listener like this:

    Code:
            new Ext.data.GroupingStore({
                storeId: 'memberStore',
                reader: new Ext.data.JsonReader({fields: Member}),
                sortInfo: {field: 'name', direction: 'ASC'},
                listeners: {
                    'add' : {
                        fn: function(store, record, index) {
    
                            Ext.each(store.getRange(), function(rec){
    
                                if(!rec.get('planId')){
                                    rec.set('plan', 'Plop');
                                    rec.set('planId', 1);
                                }
                                
                            });
    
                        }
                    }
                }
            });
    But i'm not having any success. The grid that the store belongs to ends up with an empty row and the row that's been added. Anyone any ideas how to accomplish this?

    Best

    DF

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,856
    Vote Rating
    88
      -2  

    Default

    So what EXACTLY are the params passed to an add event handler?
    Longtime Sencha engineer. Now surplus to requirements apparently...

  3. #3
    Ext User
    Join Date
    Jul 2009
    Posts
    75
    Vote Rating
    1
      0  

    Default

    Hi Animal

    @param {Store} this
    @param {Ext.data.Record[]} records The array of Records added
    @param {Number} index The index at which the record(s) were added

    I spotted I got record and records incorrect.

    So I updated my code to:

    Code:
    Ext.each(records, function(rec){
    
                                if(!rec.get('planId')){
                                    rec.set('plan', 'Plop');
                                    rec.set('planId', 1);
                                }
                                
                            });
    But I'm still getting the rogue blank row.

    Are you suggesting I've got the add listener params wrong?

    Best

    DF

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,856
    Vote Rating
    88
      -2  

    Default

    no more avoidance possible.

    you'll have to debug.
    Longtime Sencha engineer. Now surplus to requirements apparently...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •