PDA

View Full Version : getHeight returns 0 in the after render event



pinidbest
10 Jun 2012, 3:15 AM
Hi all,
I need my panel controll to get its height in the afterrender event and it returns 0.
Any idea?

I am using fit layout

scottmartin
10 Jun 2012, 7:40 AM
I noticed if you did not specify the height, the value was incorrect without the delay.
If you specified the height, then it was accurate even without the delay.



Ext.create('Ext.panel.Panel', {
title: 'Hello',
width: 200,
height: 50,
html: '<p>World!</p>',
renderTo: Ext.getBody(),
listeners: {
delay: 1, // time to finish
afterrender: function(panel) {
var ph = panel.getHeight();
console.log(ph);

}
}
});


Regards,
Scott.

pinidbest
10 Jun 2012, 7:58 AM
So iam not specifyinh any height.

scottmartin
10 Jun 2012, 8:07 AM
Then remove the height from my example ;)

Regards,
Scott.

Animal
10 Jun 2012, 11:37 AM
Delays are evil.

And I don't throw that term about much. eval is not evil.

The Panel has not received its first layout afterrender.

Use this:



Ext.create('Ext.panel.Panel', {
title: 'Hello',
width: 200,
html: '<p>World!</p>',
renderTo: Ext.getBody(),
listeners: {
afterlayout: function(panel) {
var ph = panel.getHeight();
console.log(ph);
}
}
});

scottmartin
10 Jun 2012, 1:38 PM
Delays are evil.

Good to know. This solution has always bothered me. Thanks!

Scott.