1. #1
    Sencha User
    Join Date
    Feb 2009
    Location
    Orlando, FL
    Posts
    83
    Vote Rating
    0
    jimmifett is on a distinguished road

      0  

    Default Answered: Refresh RowNumberer after store.insert() ?

    Answered: Refresh RowNumberer after store.insert() ?


    After a store.insert(0, record), I end up like this:

    1 data1 data2
    1 data1 data2
    2 data1 data2
    3 data1 data2
    4 data1 data2
    etc.

    How can I get the rownumberer to reset after the insert?

  2. If you look at how it works, you will see that RowNumberer :: renderer uses
    record.indexOfTotal(Record)

    When you insert the record, there is no record.index value, .. so it returns 0 twice, hence you see 1, 1, 2, 3, 4.

    You could override record.indexOfTotal() to fix thjis.

    Code:
    Ext.override(Ext.grid.RowNumberer, {
    
        renderer: function(value, metaData, record, rowIdx, colIdx, store) {
            var rowspan = this.rowspan;
            if (rowspan){
                metaData.tdAttr = 'rowspan="' + rowspan + '"';
            }
    
            metaData.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
            
            console.log(store.indexOfTotal(record));
            console.log(store.getTotalCount());
            console.log(store.data.items.length);
            console.log(record);
            console.log('**');
            
            return store.indexOfTotal(record) + 1;
        }
    });
    
    var store = Ext.create('Ext.data.Store', {
        storeId : 'simpsonsStore',
        fields  : ['name', 'email', 'change'],
        data    : {'items' : [
            { 'name' : 'Lisa',  'email' : 'lisa@simpsons.com',  'change' : 100  },
            { 'name' : 'Bart',  'email' : 'bart@simpsons.com',  'change' : -20  },
            { 'name' : 'Homer', 'email' : 'home@simpsons.com',  'change' : 23   },
            { 'name' : 'Marge', 'email' : 'marge@simpsons.com', 'change' : -11  }
        ]},
        proxy   : {
            type   : 'memory',
            reader : {
                type : 'json',
                root : 'items'
            }
        }
    });
    
    var grid = Ext.create('Ext.grid.Panel', {
        title      : 'Simpsons',
        store      : Ext.data.StoreManager.lookup('simpsonsStore'),
        columns    : [
            { xtype: 'rownumberer' },
            { header : 'Name', dataIndex : 'name' },
            { header : 'Email', dataIndex : 'email', flex : 1 },
            { header : 'Change', dataIndex : 'change' }
        ],
        height     : 200,
        width      : 400,
        renderTo   : Ext.getBody()
    });
    
    myrec = { name: 'new name'};
    store.insert(0,myrec);
    console.log('-----------------------');
    console.log(store.data.items.length);
    Scott.

  3. #2
    Sencha Premium Member Zdeno's Avatar
    Join Date
    Nov 2009
    Location
    Prague
    Posts
    326
    Vote Rating
    12
    Answers
    5
    Zdeno will become famous soon enough

      0  

    Default


    Try call
    Code:
    grid.getView().refresh();
    after insert.

  4. #3
    Sencha User
    Join Date
    Feb 2009
    Location
    Orlando, FL
    Posts
    83
    Vote Rating
    0
    jimmifett is on a distinguished road

      0  

    Default


    First thing I tried

    Have done after insert call, inside an add listener on the store, and manually refreshing from console.

  5. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    7,185
    Vote Rating
    194
    Answers
    433
    scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold scottmartin is a splendid one to behold

      0  

    Default


    If you look at how it works, you will see that RowNumberer :: renderer uses
    record.indexOfTotal(Record)

    When you insert the record, there is no record.index value, .. so it returns 0 twice, hence you see 1, 1, 2, 3, 4.

    You could override record.indexOfTotal() to fix thjis.

    Code:
    Ext.override(Ext.grid.RowNumberer, {
    
        renderer: function(value, metaData, record, rowIdx, colIdx, store) {
            var rowspan = this.rowspan;
            if (rowspan){
                metaData.tdAttr = 'rowspan="' + rowspan + '"';
            }
    
            metaData.tdCls = Ext.baseCSSPrefix + 'grid-cell-special';
            
            console.log(store.indexOfTotal(record));
            console.log(store.getTotalCount());
            console.log(store.data.items.length);
            console.log(record);
            console.log('**');
            
            return store.indexOfTotal(record) + 1;
        }
    });
    
    var store = Ext.create('Ext.data.Store', {
        storeId : 'simpsonsStore',
        fields  : ['name', 'email', 'change'],
        data    : {'items' : [
            { 'name' : 'Lisa',  'email' : 'lisa@simpsons.com',  'change' : 100  },
            { 'name' : 'Bart',  'email' : 'bart@simpsons.com',  'change' : -20  },
            { 'name' : 'Homer', 'email' : 'home@simpsons.com',  'change' : 23   },
            { 'name' : 'Marge', 'email' : 'marge@simpsons.com', 'change' : -11  }
        ]},
        proxy   : {
            type   : 'memory',
            reader : {
                type : 'json',
                root : 'items'
            }
        }
    });
    
    var grid = Ext.create('Ext.grid.Panel', {
        title      : 'Simpsons',
        store      : Ext.data.StoreManager.lookup('simpsonsStore'),
        columns    : [
            { xtype: 'rownumberer' },
            { header : 'Name', dataIndex : 'name' },
            { header : 'Email', dataIndex : 'email', flex : 1 },
            { header : 'Change', dataIndex : 'change' }
        ],
        height     : 200,
        width      : 400,
        renderTo   : Ext.getBody()
    });
    
    myrec = { name: 'new name'};
    store.insert(0,myrec);
    console.log('-----------------------');
    console.log(store.data.items.length);
    Scott.

  6. #5
    Sencha User
    Join Date
    Feb 2009
    Location
    Orlando, FL
    Posts
    83
    Vote Rating
    0
    jimmifett is on a distinguished road

      0  

    Default


    Thanks Scott!
    That helped point me in the right direction!

    I add:
    Code:
    if(record.phantom)
         { return '*'; }
    before the regular return in the override.

  7. #6
    Sencha Premium Member
    Join Date
    Jun 2012
    Posts
    64
    Vote Rating
    2
    Answers
    4
    benjamineberle is on a distinguished road

      0  

    Default


    Scott,
    Can we expect that the renderer's store.indexOfTotal() gets replaced with store.indexOf() sometimes soon?
    Rownumberer is anyway not a key, so I guess this would be the more natural behaviour.
    Just trying to avoid overrides for later maintenance...
    Thanks