最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to create dynamic CSS class in in extjs or javascript - Stack Overflow

programmeradmin5浏览0评论

is it possible to create dynamic css class for the GridView in extjs without hard coding the css class inside style sheet, for example

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

is it possible to create dynamic css class for the GridView in extjs without hard coding the css class inside style sheet, for example

 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.
   }
 };
Share Improve this question edited Aug 13, 2012 at 17:35 Neil McGuigan 48.3k12 gold badges129 silver badges155 bronze badges asked Aug 12, 2012 at 21:27 Edison OuyangEdison Ouyang 531 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You could use Ext.util.CSS.createStyleSheet (available both in ExtJS 3.4 and ExtJS 4.1) for that exact purpose.

Sample:

Ext.util.CSS.createStyleSheet(
    '.some-row-class {background-color:' + DEFAULT_ROW_COLOR + ';}'
);
发布评论

评论列表(0)

  1. 暂无评论