PDA

View Full Version : Cannot rely on panel.body.dom.innerHTML for panel's HTML



george4buxton
8 May 2014, 5:57 AM
I've seen a number of answers on this forum dating back to 2011/12 stating that, in order to get a panel's HTML, it is as easy as


panel.body.dom.innerHTML

I'm on ExtJS 4.2.1 and tried this but it returned HTML that included an outerCt span and innerCt div before the actual HTML I'd set when configuring the panel. To get at the actual HTML entails a couple more lines not unlike the following, but what I wish is that, since I can set the config, I should be able to get it back with a simple method call such as getHtml():



panelHtml = (function (panel) {
var panelInnerCtId = panel.body.dom.id.replace('-body', '-innerCt');
return Ext.dom.Query.selectNode("#" + panelInnerCtId).innerHTML;
})(myPanel);

george4buxton
12 May 2014, 5:25 AM
So has anybody else had to dig deeper into a nested DOM structure to get an "innerCt" corresponding to the body, or am I possibly doing something wrong? Thanks in advance.

jsakalos
12 May 2014, 8:33 AM
In majority of cases you don't need html in Ext application, why and what for it is needed in you case? Where the panel body content comes from?

It is inevitable unreliable as for some layouts innerCt is used but for some not.

george4buxton
13 May 2014, 8:01 AM
My use case is irrelevant. Not providing a simple way to retrieve a panel's HTML is a deficiency. However since relying on innerCt may be "inevitable (sic) unreliable" I present the following solution:



panelHtml = (function (panelArg) {
var panelInnerCtId = panelArg.body.dom.id.replace('-body', '-innerCt');
var panelInnerCtEl = Ext.dom.Query.selectNode("#" + panelInnerCtId);

if (panelInnerCtEl) {
return panelInnerCtEl.innerHTML;
}
else {
return panel.body.dom.innerHTML;
}
})(panelArgIn);

jsakalos
13 May 2014, 11:16 AM
Well, I'm with Ext since 2007, written, consulted and supervised many big apps development and during all this time I've never seen that necessity of getting panel's body html.

Ext normally generates the html, not analyzes/uses the html generated elsewhere.

Don't take me wrong, I'm not saying that your requirement is not valid or that you don't have a use for it.

You might be interested in reading this: Changing the viewpoint to Ext (http://extjs.eu/changing-the-viewpoint-to-ext/)

george4buxton
13 May 2014, 11:40 AM
Hi Saki, I've been using ExtJS the vast majority of the time since Jan 2009, probably 50 of the last 64 months, and sure this is the first time that I need to get a panel's HTML, but others have been asking for this ability and it doesn't seem to be unreasonable that this should be able to do in an easy and reliable manner. I'm hoping my own accepted answer helps somebody.

Here are some of those other questions regarding this:

http://www.sencha.com/forum/showthread.php?152882-get-html-from-panel
http://stackoverflow.com/questions/12691538/how-get-html-content-from-panel-in-extjs

jsakalos
13 May 2014, 11:46 AM
Maybe it is worth a feature request then.