PDA

View Full Version : Select individual items from actioncolumn from the controller?



norbergh
14 Dec 2011, 8:26 AM
I have an actioncolumn containing two items and I would like to avoid having to use the handler functions because I want all handling to be done in the controller.

So, is it possible to write a query that selects only one of the two items?

I have tried a lot of different queries, for example: 'grid actioncolumn *[tooltip=historik]' but I can't seem to get it to work since the items don't have an x-type.


{
xtype: 'actioncolumn',
width: 35,
sortable: false,
menuDisabled: true,
items: [
{
icon: 'icons/pencil.png',
tooltip: 'Ă„ndra'
},
{
icon: 'pics/audit.gif',
tooltip: 'Historik'
}
]
}

mitchellsimoens
15 Dec 2011, 2:07 PM
The icons are just img tags.. they aren't components so you won't be able to use ComponentQuery to get to them. You could specify the handler on the items and fire an event on the grid (or action column) for the img click.

norbergh
15 Dec 2011, 2:30 PM
That's what I ended up doing. Fired two different events in the handlers and listened to them in the controller.

Did not take down the post however cause I wanted to know if it was possible. So thanks for the answer, will be good to know for future reference that it's just not possible to query things without x-type.

nixerella
27 Jan 2012, 5:06 AM
I am trying to do this as suggested, i.e. fire a different event in each handler, but for some reason only one listener in the controller works. It's the second one, so if I swap the order in the controller the other one works and the originally working one doesn't.
In the controller's init I have:
this.control({
'viewport mygridname' : {gridRowDelete: this.doDelete},
'viewport mygridname' : {gridRowView: this.doView}
});
(in the above, the doDelete isn't called when I click the delete, but if I swap the 2 listeners the doView doesn't fire)

in the view I have an xtype of actioncolumn with 2 items each with an icon, tooltip, action, id and handler. In the respective handlers I do
this.fireEvent('gridRowDelete',param1, param2);
his.fireEvent('gridRowView',param1, param2);

Can someone advise or post a working example. I don't actually need 2 items in the action column - I'd prefer the itemclick on the grid to do the view logic but I couldn't get that working either.

Thanks

norbergh
27 Jan 2012, 5:35 AM
This works for me.


{
xtype: 'actioncolumn',
width: 35,
sortable: false,
menuDisabled: true,
items: [
{
icon: 'icons/pencil.png',
tooltip: 'Edit',
handler: function(grid, rowIndex, coldIndex, item) {
var rec = grid.getStore().getAt(rowIndex);

this.fireEvent('editclick', {
record: rec
});
}
},
{
icon: 'icons/audit.gif',
tooltip: 'History',
handler: function(grid, rowIndex, colIndex, item) {
var rec = grid.getStore().getAt(rowIndex);

this.fireEvent('historyclick', {
record: rec
});
}
}
]
}



'actioncolumn': {
historyclick: this.openHistoryWin,
editclick: this.openEditWin
}

nixerella
27 Jan 2012, 6:19 AM
Thanks, I'd not spotted that my controller listener code was wrong - I basically had two identical selectors for the actioncolumn, but yours had the one selector with the two events. When I made mine like that it worked.