tags:

views:

2082

answers:

3

I currently have two panels within another large panel. The left panel is for navigation and the right is for content. I'm trying to modify the content panel background color so I have made an event that triggers on expandnode, and this is where I am stuck.

My right panel ID is #panneau-affichage and I'm trying to modify the background-color attribute of the class x-panel-body that lives within. Using:

Ext.get('panneau-affichage').setBodyStyle('backgroundColor : #dddddd');

Firebug states that there is no such function, and with:

Ext.get('panneau-affichage').applyStyle('backgroundColor: #dddddd);

This does the job for the div but is overridden by x-panel-body.

A: 

Why don't you just set it via CSS? Use Firebug to drill down to panel's body div element. Write your own override using your panel's id. This way it will work without Javascript, and always and even before you start running your scripts.

Using CSS class names
If you're not looking into permanent changes and settings it would still be much better to define a CSS class and add/remove the class to panel itself and set panel's body style via CSS. It would be centralised and much better customizable. And it would keep style away from your code, which you should always thy to achieve. Separate code from visuals.

Robert Koritnik
I can't, I am not using this to set a permanent state. I need to change background-color on certain triggers.
Balls-of-steel
check my "Edit".
Robert Koritnik
A: 

You are using Ext.get(). This returns an Ext.Element object, which doesn't have the setBodyStyle() function. The Ext.Element is not a HTML node, but you can see it like a wrapper for it.

The correct function for you to use would be setStyle( String/Object property, [String value] ). If I am not entirely mistaken, for your need this should work:


Ext.get('panneau-affichage').setStyle('backgroundColor','#dddddd');
Johannes
I kind of understand that ext.element does not have a setBodyStyle but your guess of .setStyle does the same thing that the .applyStyle I have mention earlier, it set the background fine for "panneau-affichage" but it is overrunned by the x-panel-body just after.
Balls-of-steel
Ext wraps panels normally in three divs. If you need to set the background, you need to do it on the last of those three.You can test this on ExtJs's sample page:http://extjs.com/deploy/dev/examples/panel/panels.htmlGo to the firebug console and use this function:Ext.get('panel-basic').first().last().first().setStyle('background','lightblue')Note- The div with id panel-basic is the one that is the container for the panel and it is not part of the three panel related divs.- You need to use ...first().last()... since first().first() would return the header of the panel.
Johannes
A: 

Solution for this:

Ext.getCmp('panel-id').body.setStyle('background','lightblue');

Thanks, Sridhar

Sridhar