PDA

View Full Version : Setting "defaultUnit" to use percentage



bertoneill
20 Jan 2014, 8:49 AM
Hi
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?

Thanks
Bert

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



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

bertoneill
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?

Malte123
20 Jan 2014, 11:33 AM
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.AbstractComponent-method-setHeight


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 ?

Maybe:



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

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

Malte123
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)