2016-02-04 56 views
1

我想创建一个网格,每行都有不同的样式(字体,颜色,背景颜色等)。样式是一个字符串数组(每个都有CSS代码),其长度与网格中的行数相同。 我的问题是,我找不到一个解决方案,将每行的样式设置为存储在我的数组中的样式。 我创建的网格看起来是这样的:网格中的样式行

newGrid = Ext.create('Ext.ux.Grid', { 
     store: tableStore, 
     columns: gridColumns, 
    }); 

和阵列看起来很像styles[]

任何帮助将不胜感激!

回答

0

这里是working fiddle

var myStyles = [ 
     { 
      backgroundColor: 'red' 
     }, 
     { 
      backgroundColor: 'green', 
      fontWeight: 'bold' 
     }, 
     { 
      backgroundColor: 'blue' 
     }, 
     { 
      backgroundColor: 'yellow', 
      fontStyle: 'italic' 
     } 
]; 

myStore.getData().each(function(record){ 
    // You can map grid store records with styles array in any other way, 
    // for example purposes I just use row internalId 
    var recordId = record.internalId - 1; 

    for(var propertyName in myStyles[recordId ]) { 
     myGridView.getRow(record).style[propertyName] = myStyles[recordId][propertyName]; 
    } 
}); 

Ext.view.Table.getRow()返回HTML元素,所以你可以用它操控与JS你想要的任何方式,阅读HTMLElement.classNameHTMLElement.style例如。

此外,借助更多的附加代码,您可以根据例如记录特定属性值将样式数组与网格记录进行映射。