View Full Version : Sequence of events when adding a new component to a container

3 Jan 2011, 2:27 PM
Can I always rely on this observation? That when a new component is added to an existing container (i.e. adding a tab to a tabpanel), that the new component won't be rendered until I call doLayout() on the container?

3 Jan 2011, 3:12 PM
You are certainly expected to call doLayout() after adding a new component. This is by design, see the docs for Ext.Container.add(). However, I wouldn't rely on not calling doLayout() as a way of temporarily hiding the new child. Something else (such as a browser resize) could fire off doLayout() calls before you're ready.

From the docs for Ext.Container.add():

you may need to call doLayout to refresh the viewThe use of the word 'may' leaves it open for subclasses to remove this requirement. However, I don't know of any standard components/containers that would not require the call to doLayout().

3 Jan 2011, 3:52 PM
Right. I'm not trying to temporarily hide the new child, just making sure I didn't have a race condition. I need to add the new component to the container and then set some properties on it before it renders. So as long as I do this before calling doLayout, I should be fine, right?

3 Jan 2011, 3:59 PM
That should be fine but why not just set the properties before you add it to the container?

3 Jan 2011, 4:02 PM
Yeah. I thought of that, but this particular case is a bit convoluted.