如何在extjs或javascript中创建动态CSS类

时间:2012-08-12 21:28:00

标签: javascript css extjs

是否可以在extjs中为GridView创建动态css类,而无需在样式表中对css类进行硬编码,例如

 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.
   }
 };

1 个答案:

答案 0 :(得分:6)

您可以使用Ext.util.CSS.createStyleSheet(ExtJS 3.4和ExtJS 4.1中都有)用于此目的。

样品:

Ext.util.CSS.createStyleSheet(
    '.some-row-class {background-color:' + DEFAULT_ROW_COLOR + ';}'
);
相关问题