ExtJS5 : FireEvent from View to Controller

Sometimes, I need to fire up an event from a component/a view to the main controller.

1st, my view, here a compnonent based on a grid panel from which I want to fire a specific event when an object is selected:

Ext.define('NameSpace.ux.SitesGrid',{
     extend: 'Ext.grid.Panel',
[...]
// fired when the line/object is selected
,onObjectSelect:function(grid, obj, index, eOpts) {
    this.fireEvent('MySpecificEvent', this, obj));
} // eo function onObjectSelect

So, when an object is selected, “MySpecificEvent” is fired up

Usually, “main MVC” is splitted in 3 files: the View, the Controller, and the Model.

In the main view, defined your listener for your specific event

Ext.define('NameSpace.view.main.Main', {
    extend: 'Ext.container.Container'
[...]
,listeners: {
    MySpecificEvent: function(src, obj) {
        console.info('MySpecificEvent event occurs', src, obj);}
    }

and that’s all !!!

Typically, I used this kind of stuff to notify route change to the main controller quite easily.

You can also fire event to the Application level, but it is not really recommended. in that case, to fire the event:

NameSpace.getApplication().fireEvent('MySpecificEvent', this, obj));