-
29 Nov 2011 10:44 PM #1
Answered: How to get the rendered HTML of a component.
Answered: How to get the rendered HTML of a component.
Hi all,
Is there anyway to get the html code rendered by Ext engine in displaying a component.
Thanks in advance.
-
Best Answer Posted by tvanzoelen
After render it possible to see the created html
Code:component.getEl().dom.innerHTML;
-
30 Nov 2011 12:38 AM #2Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,017
- Vote Rating
- 23
- Answers
- 75
After render it possible to see the created html
Code:component.getEl().dom.innerHTML;
-
30 Nov 2011 1:24 AM #3
I am writing this getEl method on a Ext.form.FieldSet, But it is saying the method is undefined.prob.jpg
-
30 Nov 2011 1:29 AM #4Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,017
- Vote Rating
- 23
- Answers
- 75
Are you calling the function before or after render? The element is only available after render.
-
30 Nov 2011 1:35 AM #5
after render only I am calling the function.
-
30 Nov 2011 2:03 AM #6Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,017
- Vote Rating
- 23
- Answers
- 75
show me code then
-
30 Nov 2011 2:31 AM #7
Ext.define('LNM.view.newAccount.NewAccountForm' ,{
extend: 'Ext.form.Panel',
alias : 'widget.NewAccountForm',
title:'Create New Account',
frame: true,
bodyStyle: 'padding:15 15 15 15',
autoScroll: true,
height:400,
items: [{
xtype: 'fieldset',
title: 'Estate Information',
collapsible: true,
layout: 'anchor',
anchor: '100%',
items:[{
xtype: 'textfield',
anchor:'30%',
labelWidth: 100,
fieldLabel: 'Estate Location',
name:'estateLocation',
flex: 1
},{
xtype: 'textfield',
anchor:'30%',
labelWidth: 100,
fieldLabel: 'Estate Officer',
name:'estateOfficer',
flex: 1
},{
xtype: 'textfield',
anchor:'30%',
labelWidth: 100,
fieldLabel: 'Estate Assistant',
name:'estateAssistant',
flex: 1
},{
xtype: 'textfield',
anchor:'30%',
labelWidth: 100,
fieldLabel: 'Estate Comments',
name:'estateComments',
flex: 1
}]
},{
buttonAlign: 'center',
buttons: [{
text: 'Reset',
handler: function() {
this.up('form').getForm().reset();
}
}, {
text: 'Submit',
formBind : true,
id:'newaccountSubmitButton'
}]
}], // End of CallTrackForm items
initComponent: function() {
this.callParent(arguments);
}
});
This is my panel.
var accountPanel = Ext.widget('NewAccountForm');
accountPanel.getEl().dom.innerHtml; // This line is in the handler of a button and it throws the error getEl is undefined.
accountPanel.getEl().dom.innerHTML;
-
30 Nov 2011 2:43 AM #8Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,017
- Vote Rating
- 23
- Answers
- 75
If I do like below I get de innerHTML.
Code:Ext.onReady(function() { Ext.define('LNM.view.newAccount.NewAccountForm', { extend: 'Ext.form.Panel', alias: 'widget.NewAccountForm', title: 'Create New Account', frame: true, bodyStyle: 'padding:15 15 15 15', autoScroll: true, height: 400, renderTo: Ext.getBody(), items: [{ xtype: 'fieldset', title: 'Estate Information', collapsible: true, layout: 'anchor', anchor: '100%', items: [{ xtype: 'textfield', anchor: '30%', labelWidth: 100, fieldLabel: 'Estate Location', name: 'estateLocation', flex: 1 }, { xtype: 'textfield', anchor: '30%', labelWidth: 100, fieldLabel: 'Estate Officer', name: 'estateOfficer', flex: 1 }, { xtype: 'textfield', anchor: '30%', labelWidth: 100, fieldLabel: 'Estate Assistant', name: 'estateAssistant', flex: 1 }, { xtype: 'textfield', anchor: '30%', labelWidth: 100, fieldLabel: 'Estate Comments', name: 'estateComments', flex: 1 }] }, { buttonAlign: 'center', buttons: [{ text: 'Reset', handler: function() { this.up('form').getForm().reset(); } }, { text: 'Submit', formBind: true, id: 'newaccountSubmitButton' }] }], // End of CallTrackForm items initComponent: function() { this.callParent(arguments); } }); var form = Ext.create('LNM.view.newAccount.NewAccountForm', { listeners: { render: { fn: function(c) { var d = c.getEl().dom.innerHTML; console.log(d); } } } }); });
-
30 Nov 2011 2:44 AM #9Sencha User
- Join Date
- Dec 2009
- Location
- Enschede, The Netherlands
- Posts
- 327
- Vote Rating
- 11
- Answers
- 16
Please use code tags, the code above is (almost) impossible to use.
I think the issue is that you are instantiating the component (using Ext.widget()), but that doesn't mean it gets rendered. I think that when you do this it will work:
Code:var accountPanel = Ext.widget('NewAccountForm', { renderTo: Ext.getBody() }); accountPanel.getEl().dom.innerHtml; // This line is in the handler of a button and it throws the error getEl is undefined.
-
30 Nov 2011 2:48 AM #10Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,017
- Vote Rating
- 23
- Answers
- 75
Yes I have put that in my example as well
but you can also render it on a div or add the field set to a formpanel.Code:renderTo: Ext.getBody(),


Reply With Quote