PDA

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



mazhar.shaikh
19 Mar 2013, 12:46 PM
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

slemmon
19 Mar 2013, 12:53 PM
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.



Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'Lisa', "email":"[email protected]", "phone":"555-111-1224" },
{ 'name': 'Bart', "email":"[email protected]", "phone":"555-222-1234" },
{ 'name': 'Homer', "email":"[email protected]", "phone":"555-222-1244" },
{ 'name': 'Marge', "email":"[email protected]", "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);
}
}]
});

mazhar.shaikh
19 Mar 2013, 1:08 PM
Appreciate it mate!! Working!!

Cheers