1. #1
    Sencha User
    Join Date
    Feb 2013
    Location
    NZ
    Posts
    74
    Answers
    5
    Vote Rating
    0
    mazhar.shaikh is on a distinguished road

      0  

    Default Answered: How can I set the one particular column of a grid panel to 0?

    Answered: How can I set the one particular column of a grid panel to 0?


    How can I set the one particular column of a grid panel to 0? Irrespective of whatever data is present in that column, I just want to set the entire column to 0. (like a reset). Its a numeric column.
    Using Extjs4.1

    thanks

  2. I take it your column is using a dataIndex to use a field in a record/model as its value, yes?
    If so, just iterate through the store and set the value of each record to 0 and that'll update the column.

    Code:
    Ext.create('Ext.data.Store', {
        storeId:'simpsonsStore',
        fields:['name', 'email', 'phone'],
        data:{'items':[
            { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224"  },
            { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
            { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244"  },
            { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }
        ]},
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'items'
            }
        }
    });
    
    
    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: Ext.data.StoreManager.lookup('simpsonsStore'),
        columns: [
            { text: 'Name',  dataIndex: 'name' },
            { text: 'Email', dataIndex: 'email', flex: 1 },
            { text: 'Phone', dataIndex: 'phone' }
        ],
        height: 200,
        width: 400,
        renderTo: Ext.getBody()
        , tbar: [{
            text: 'Set name to \'mazhar\''
            , handler: function (btn) {
                var store = btn.up('gridpanel').getStore();
                
                Ext.suspendLayouts();
                store.each(function (record) {
                    record.set('name', 'mazhar');
                });
                Ext.resumeLayouts(true);
            }
        }]
    });

  3. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,417
    Answers
    434
    Vote Rating
    201
    slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of

      0  

    Default


    I take it your column is using a dataIndex to use a field in a record/model as its value, yes?
    If so, just iterate through the store and set the value of each record to 0 and that'll update the column.

    Code:
    Ext.create('Ext.data.Store', {
        storeId:'simpsonsStore',
        fields:['name', 'email', 'phone'],
        data:{'items':[
            { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224"  },
            { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
            { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244"  },
            { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }
        ]},
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'items'
            }
        }
    });
    
    
    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: Ext.data.StoreManager.lookup('simpsonsStore'),
        columns: [
            { text: 'Name',  dataIndex: 'name' },
            { text: 'Email', dataIndex: 'email', flex: 1 },
            { text: 'Phone', dataIndex: 'phone' }
        ],
        height: 200,
        width: 400,
        renderTo: Ext.getBody()
        , tbar: [{
            text: 'Set name to \'mazhar\''
            , handler: function (btn) {
                var store = btn.up('gridpanel').getStore();
                
                Ext.suspendLayouts();
                store.each(function (record) {
                    record.set('name', 'mazhar');
                });
                Ext.resumeLayouts(true);
            }
        }]
    });

  4. #3
    Sencha User
    Join Date
    Feb 2013
    Location
    NZ
    Posts
    74
    Answers
    5
    Vote Rating
    0
    mazhar.shaikh is on a distinguished road

      0  

    Default Solved.

    Solved.


    Appreciate it mate!! Working!!

    Cheers

Thread Participants: 1

Tags for this Thread