Edi*_*ang 5 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.
}
};
Run Code Online (Sandbox Code Playgroud)
您可以使用Ext.util.CSS.createStyleSheet
(在ExtJS 3.4和ExtJS 4.1中都可用)来实现这个目的.
样品:
Ext.util.CSS.createStyleSheet(
'.some-row-class {background-color:' + DEFAULT_ROW_COLOR + ';}'
);
Run Code Online (Sandbox Code Playgroud)