I have an extjs4 panel created using this config object.
{
title : 'Messages',
region : 'north',
height : 200,
minSize : 75,
maxSize : 250,
cmargins : '0 0 5 0',
html : '<i>Chat started on ' + Ext.Date.format(dt, EI.datePattern) + '</i>'
}
Now I want to append more html on it. For example I want to append
<p><span class="user">me:</span><span class="how are you?"></span></p>
Sometimes I could append using
thePanel.body.insertHtml("beforeEnd", chatHtml);
But I see sometimes .body is not set!! So I can not execute the above code. What is the proper way to do it?
The body element of a panel isn’t available until after the panel’s render event has fired. This is the same for all elements that are listed under the
childElsconfig of any component.There are a few different ways an element can be rendered. This isn’t a comprehensive list.
If a component is a child item of a container, then the component will be rendered when the parent container renders. The exception to this is containers using card layout, such as a tab panel, when using the
deferredRenderconfig.If a component is not a child of a container, but it is using the
renderToconfig, it will be rendered upon construction, even if it is hidden.If a non-floating component is using the
autoRenderconfig, that component will render the first time it is shown, such as withpanel.show(). If it is using bothautoRenderandautoShowthen it will be rendered upon construction.Floating components such as windows default to
autoShow: falseandautoRender: true, so they will not render until you callwin.show(). If you setautoShowto true, it will render on creation.Floating components using the
renderToconfig will render on creation and stay hidden, unless also usingautoShowas mentioned above.It sounds like you have a panel that is a child of a window, correct? To get that panel to render immediately but stay hidden, set
renderTo: Ext.getBody()on the parent window.Alternatively, you can still access the
panel.htmlproperty before the panel is rendered, and any changes will be reflected when the window is shown. So if you need to access the inner content but you can’t guarantee the panel has been rendered, you might do something like this:One last thing. If you set the
htmlconfig of a panel then render it, there will be an extra div called theclearElafter your original content. Callingpanel.body.insertHtml()after render will place the new HTML after this div. This may or may not be a problem for you, but I thought I’d mention it anyway.