I'am new to extJS and maybe I just don't know the correct strategy, so you can tell me a better solution if you want to.
What I'am trying: I've got an extJS Grid. On a doubleclick, an ExtJS Window container (for detailed settings) should appear which has multiple tabs in it. The window has got a function to set the ID of the clicked element. Every tab in the window needs this ID too. So I want to inform every tab container via an event about the changed ID, when the ID is changed in the window container.
My problem is, that I can't access the window from the tabs to add a listener, because the window is not rendered until it is opened the first time.
Maybe you can understand my problem better if you take a look on my sourcecode:
the Window (setCustomerId() and show() is called, when doubleclicking on a grid element)
Ext.define('myApp.path.view.Edit', {
extend: 'Ext.window.Window',
alias: 'widget.myEdit',
title: 'Edit',
height: 500,
width: 1000,
layout: 'fit',
closeAction: 'hide',
/**
* Initialize my custom event
*/
initComponent: function() {
this.addEvents('customerChanged');
this.callParent();
},
/**
* Sets the current customerId and fires a customerChanged event
* @param {Number} customerId
*/
setCustomerId: function(customerId) {
this.customerId = customerId;
this.fireEvent('customerChanged', this.customerId);
},
/**
* create a container for the editor tabs
*/
items: [{
xtype: 'tabpanel',
items: [
{
xtype: 'myTab'
}
]
}]
})
an example tab
Ext.define('myApp.path.view.myTab', {
extend: 'Ext.container.Container',
alias: 'widget.myTab',
title: 'Customer',
layout: 'fit',
/**
* Listen to my custom event
* PROBLEM: works, but only after the window has been displayed one time
*/
afterRender: function() {
this.findParentByType('window').addListener("customerChanged", this.onCustomerChanged)
this.callParent();
},
/**
* Listen to my custom event
* PROBLEM: doesn't work, findParentByType('window') is undefined
*/
initComponent: function() {
this.findParentByType('window').addListener("customerChanged", this.onCustomerChanged)
this.callParent();
},
onCustomerChanged: functio() {}
})
I hope you can understand my intension. Thank you!
afterRender
function is being called after the window has been rendered (and initComponent is being called straight after it's being constructed, before it is being rendered or added). Btw, what do your tabs needed to know before the window even get created? I don't see the intention that you need the id before your window is being added ;) – Lionel Chan