I have this gridPanel:
Ext.define('BM.view.test.MacroList', {
extend: 'BM.view.GridPanel',
alias:'widget.macro-test-list',
store: 'Tests',
initComponent: function() {
this.columns = [
{
xtype:'actioncolumn',
width:50,
items: [
{
icon: 'images/start.png',
tooltip: 'Start Test',
handler: function(grid, rowIndex, colIndex) {
this.application.fireEvent('testStart', grid.getStore().getAt(rowIndex));
// application not defined here because 'this' is the button.
}]
}]
}
}
stratTest is a function that will be available from many places in the application, and I would like it to be used as an application wide event, but those seem to be available only from controllers.
How do I call .application.fireEvent('testStart'...) from the handler inside this button?
I’m using this question as a constant reference to events, and the Sencha docs, but couldn’t find the answer.
You get
this.applicationwithin a controller scope.Given you are clearly using MVC here, I’d say it’s best to stick to MVC concepts; that is, for reusability sake, a component shouldn’t know what controller uses it, but rather a controller should know what components it is using.
So you should really listen to the event in the controller, and fire an application event from there.
The problem is that there’s no access to the actioncolumn handler from the controller (it is called internally in
Ext.grid.column.ActionprocessEvent()).So your best shot is to fire a new event in the view:
Notice also that you can define a global handler for the column, like so:
And then catch this event in the controller.
Notice, by the way, that given what you are trying to do, a cleaner code would be: