PDA

View Full Version : Add colum on gridPanel



15 Sep 2012, 7:27 AM
Hi all,
i'm looking for add column on gridPanel.
With add method no firebug error appear but layout don't change.


var grid = new Ext.create('Ext.grid.Panel', {
title: 'List',
id: 'grid',
flex: 1,
store: 'storeGrid',
columns: [
new Ext.grid.RowNumberer(),
{
text: 'Prelievo',
flex: 1,
columns:[
{ header: "Label a", dataIndex: 'preA', flex:1},
{ header: "Delta", dataIndex: 'preB', flex:1}
]
}
]
});



var newCol = Ext.create('Ext.grid.column.Column', {
{
text: 'New Column',
flex: 1,
columns:[
{ header: "Label B", dataIndex: 'preC', flex:1},
{ header: "Delta", dataIndex: 'preD', flex:1}
]
}
});
grid.add(newCol);
grid.doLayout();



THX

scottmartin
15 Sep 2012, 1:06 PM
In your column object, your are adding an array of columns:

Try this:


Ext.create('Ext.data.Store', {
storeId : 'simpsonsStore',
fields : ['name', 'email', 'change'],
data : {'items' : [
{ 'name' : 'Lisa', 'email' : '[email protected]', 'change' : 100 },
{ 'name' : 'Bart', 'email' : '[email protected]', 'change' : -20 },
{ 'name' : 'Homer', 'email' : '[email protected]', 'change' : 23 },
{ 'name' : 'Marge', 'email' : '[email protected]', '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 : [
{ header : 'Name', dataIndex : 'name' },
{ header : 'Email', dataIndex : 'email', flex : 1 },
{ header : 'Change', dataIndex : 'change'}
],
height : 200,
width : 400,
renderTo : Ext.getBody()
});

Ext.create('Ext.Button', {
text: 'Click me',
renderTo: Ext.getBody(),
handler: function() {
var column = Ext.create('Ext.grid.column.Column', {header: 'Column'});
grid.headerCt.insert(grid.columns.length,column);
}
});


Scott

16 Sep 2012, 6:33 AM
Thanks,
it work fine.
Luca F.