View Full Version : ownerCt/findParentBy in initComponent

5 Oct 2012, 7:44 AM

I want to look for a parent in the "initComponent" function of a child component, but as I can see the ownerCt property is first available after initComponent. How can I access a parent component without the ownerCt property?

Regards, Tobias

5 Oct 2012, 8:04 AM
You may be better off overriding onAdded rather than initComponent in that case:


The relevant owner/child relationships aren't established until after the component is created.

5 Oct 2012, 8:46 AM
I have a custom gridpanel and one part of the dynamic url I want to add to the grid store's proxy is held in a parent component (in this part of the url the id of the object I'm currently working with is included. It looks like '/item=123'). So I override the "initComponent" function of the Ext.grid.Panel and now I want to create a store like:

var url = this.ownerCt.url + '/subdata1';
// url is now "/item=123/subdata1"
this.store = Ext.create('Ext.data.JsonStore',
{ ...
proxy: {
type: 'ajax',
url: url

So when I do this in the "onAdded" function there is already an empty store created and all events are handled by this store.

Overriding the "onAdded" function is no solution for my problem. How can I handle this?

5 Oct 2012, 10:04 AM
I see, that is a bit tricky.

From what you've described it sounds like the relevant info for building the URL should be passed to the child component as a config option rather than expecting it to go find it on its parent.

Perhaps you could just create the store in initComponent but leave the URL blank (or use a dummy URL to stop it complaining). Then update the url property on the proxy inside onAdded.

There are other things you could try. For example, you could hook into the store or proxy and have them look up the relevant info just before they perform the request. There are all sorts of events and template methods for doing that sort of thing. Feels a bit much given your requirements though, I think I'd just go with one of the approaches I've already suggested.