View Full Version : Setting "defaultUnit" to use percentage

20 Jan 2014, 8:49 AM
I am setting the height of a control by using .setHeight(10). But I wan the 10 to be represented as a percentage no a pixel size.

I think I have to change the default from "px" to something, maybe "%" or "pc" - but not sure how to do this in my js class?


20 Jan 2014, 8:58 AM
what happens if you use:

this.setHeight('10%') // this because I do not know witch scope is there :-)

20 Jan 2014, 9:21 AM
It looks like the parameter is looking for an int.

Thus I think defaultUnit needs to be set to use percentage and the value coming in the .setheight(xx) method will be classed as a percentage then?

20 Jan 2014, 11:33 AM

The new height to set. This may be one of:

A Number specifying the new height in the Element (http://docs-origin.sencha.com/extjs/4.2.1/#%21/api/Ext.AbstractComponent-method-getEl)'s Ext.Element.defaultUnit (http://docs-origin.sencha.com/extjs/4.2.1/#%21/api/Ext.dom.Element-property-defaultUnit)s (by default, pixels).
A String used to set the CSS height style.
undefined to leave the height unchanged.

This is the Text I found in the Abstract Class related to all Components - also your Control I think.

Maybe you try to use parent Method to set Height.

Or what happens if you try

this.height = '50%'

within a Method of your Component-Instance ?


// after constructor or config for example
afterRender: function(){
this.height = '50%';

21 Jan 2014, 1:52 AM
I will set the control's width like a style syntax, instead of using .setHeight(20)

21 Jan 2014, 12:02 PM
I would be happy if you select my Answer as "best answer" and vote up - because I love it B)