PDA

View Full Version : Adding a particular column to a Grid



IAmAndre
31 Mar 2014, 2:26 PM
Hi,

I'm showing a set of results in my application with a Grid (Ext.grid.Panel) and I want to add a particular column containing buttons. When I try to, I get the following error :
TypeError: headers[i].setSortState is not a function

I guess it has something to do with the fact that the others column are linked to a Store, while this one is not and therefore can't be sorted. Here is my code :


Ext.define('App.view.UsersGrid',{
extend:'Ext.grid.Panel',
store: Ext.data.StoreManager.lookup('usersStore'),
columns: [
{ text: 'Username', dataIndex: 'username', flex: 100/3},
{ text: 'Level', dataIndex: 'level', flex: 100/3},
{
text: 'Actions',
xtype:'buttongroup',
iconflex: 100/3,
items: [
{
xtype:'button',
icon:'resources/images/add_user.png'
}
]
}
]
});

I would like to add a set of buttons at every line. The buttons will be the same at every line, but I might need help to set the controllers too, I mean making sure that every button will trigger an action but taking into account the line it is related to.

Thanks

skirtle
31 Mar 2014, 4:13 PM
The problem is that your grid column isn't actually a column. ButtonGroup doesn't extend Ext.grid.column.Column.

ActionColumn provides something similar to what you're trying to do. If you really want to use button components you'll need to use a UX, e.g.:

http://www.sencha.com/forum/showthread.php?148064

Unrelated, you can simplify this:


store: Ext.data.StoreManager.lookup('usersStore'),

to just:


store: 'usersStore',

I think you've mistyped iconflex.

Also, flexes aren't percentage, they're proportions relative to each other, so there's no need to have values like 100/3. If you want them all to be the same width then just set them all to 1.

IAmAndre
31 Mar 2014, 4:29 PM
Thank you very much for your help. I also figured out how to use the handlers to trigger specific actions, like this :
handler: function(grid, rowIndex, colIndex) { It's working fine but I'd like to use a controller. Thanks