How to create a dynamic CSS class in extjs or javascript

you can create a dynamic css class for GridView in extjs without hard coding the CSS class inside the stylesheet, e.g.

 DEFAULT_ROW_COLOR = '#E0E0E0';
 ...
 var gridview = new Ext.grid.GroupingView({
  forceFit : forceFit,
  hideGroupedColumn : true,
  showGroupName : false,
  groupTextTpl: '{text}',
  getRowClass : getRowClassFunc
 });

 var getRowClassFunc = function(record, rowIndex, rowParams, store) {
   if (rowIndex == 1 ) {
     // create a dynamic class based on DEFAULT_ROW_COLOR for background color
   }  
   if (rowIndex > 1)  {
     // create a dynamic class for darker color for the background.
   }
 };
+5
source share
1 answer

You can use Ext.util.CSS.createStyleSheet(available in both ExtJS 3.4 and ExtJS 4.1) for this purpose.

Example:

Ext.util.CSS.createStyleSheet(
    '.some-row-class {background-color:' + DEFAULT_ROW_COLOR + ';}'
);
+6
source

All Articles