In ExtJS 4, what's the difference between componentCls, cls and bodyCls ?
-
Did you find the solution? – Kid Dec 09 '19 at 03:13
-
I want to know exactly about componentCls. – Kid Dec 09 '19 at 03:13
-
What is componentCls? ``` componentCls: 'toolbar-header-style' ``` – Kid Dec 09 '19 at 03:14
-
Ext.define('myapp.view.table',{ tbar:{ componentCls: 'toolbar-header-style` } listeners:{} columns:{} }) – Kid Dec 09 '19 at 03:15
-
the cls is affected to only toolbar. – Kid Dec 09 '19 at 03:15
1 Answers
ExtJS provide many options in styling the components. Each of these property have its place in implementing proper theming of your components.
cls: This is applied to the component's root element. Quoting from the docs:
An optional extra CSS class that will be added to this component's Element. This can be useful for adding customized styles to the component or any of its children using standard CSS rules.
By default, this is empty. If you need to style some child elements (by elements don't mean ExtJs components.. instead, they are HTML elements auto generated by the framework) of a component then, you can use this. For example, If you want to change background color of you's tab panel's inner area, you can do something like this:
.customCss x-box-inner {
background-color: yellow;
}
componentCls: This also gets applied to the component's root element. But, this property is meant to hold CSS styles for the component as a whole. Quoting from the docs:
CSS Class to be added to a components root level element to give distinction to it via styling.
From result point of view, both cls and componentCls gets applied to the root element. But, the are used for different purposes.
bodyCls: This is available for Panels. You will not find this styling for a button because, there is no body. If you want to provide custom styles for your panel's body region.. you can do so by setting this property.

- 19,223
- 11
- 88
- 133
-
4Thanks, can you give me a use case for when I'd want to use cls vs componentCls? I still don't get the distinction, maybe an example would help. – ABCD.ca Nov 02 '11 at 18:09
-
1This is not an advantage. It's more a drawback, because it both increases learning time, requires many referrals to the docs, and also makes developers puzzled. After almost a year of development with Ext JS, I judge it as a burden library, rather than being a helpful utility. – Saeed Neamati Jul 01 '13 at 09:06
-
So, cls is like an extra css style upon the component's default css. But im not sure how componentCls differs from cls. Can you give an example ? – Zahit O. Mar 24 '23 at 07:50