EXTJS GRID 改变单元格背景颜色的方法
第一种情况:加载数据时改变列的颜色
首先定义一个样式如下(这里以红色背景为例):
.x-grid-back-red { background: #FF0000; } {header:'摘要',dataIndex:'zhaoyao',align:'left',width:150, renderer : function(v,m){ m.css='x-grid-back-red'; return v; } } grid.getStore().on('load',function(s,records){ var girdcount=0; s.each(function(r){ if(r.get('zy')=='本期合计'){ grid.getView().getRow(girdcount).style.backgroundColor='#FFFF00'; }else if(r.get('zy')=='本年累计'){ grid.getView().getRow(girdcount).style.backgroundColor='#FF1493'; }else if(r.get('zy')=='期初余额'){ grid.getView().getRow(girdcount).style.backgroundColor='#DCDCDC'; } girdcount=girdcount+1; }); }); 效果图如下: //修改GRID某一行样式 grid.getView().addRowClass(r,css) //修改grid某一单元格样式 Ext.get(grid.getView().getCell(r,c)).addClass(css) 或 grid.getView().getRow(r).style.backgroundColor="red"; //css样式为自定义样式