Flex中关于DataGrid的不同行或列显示不同的颜色
在flex中,所有组件都可以根据自己的需要进行不同的扩展,最近在做一个flex的项目,其中由于大多都需要对后台数据显示,所以DataGrid控件就显示了其强大的作用,
今天主要讲解的就是DataGrid中不同行或列根据后天某一个字段进行不同颜色的区分,下面就把自己的代码进行讲解。
如果你是对行进行不同的颜色区分,那么你主要做的就是重写drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int)方法,
通过dataindex来获取DataGrid中对应数据索引的某一个datafield对应的字段的值如:dataProvider[dataIndex]["TRACKSTATE"].toString()=="正在处理",下面就是重写的整个代码。
package component { import flash.display.Sprite; import mx.collections.ArrayCollection; import mx.controls.DataGrid; import mx.controls.dataGridClasses.DataGridColumn; import mx.core.UIComponent; public class RowColorDataGrid extends DataGrid { public function RowColorDataGrid() { super(); } override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void { if(dataIndex < dataProvider.length&&dataProvider[dataIndex]["TRACKSTATE"].toString()=="正在处理") color=0xd71345; else if(dataIndex < dataProvider.length&&dataProvider[dataIndex]["TRACKSTATE"].toString()=="需要等待") color=0xf47920; else if(dataIndex < dataProvider.length&&dataProvider[dataIndex]["TRACKSTATE"].toString()=="需要确认") color=0xffd400; else if(dataIndex < dataProvider.length&&dataProvider[dataIndex]["TRACKSTATE"].toString()=="结题") color=0x6e6b41; else color=0xededed; super.drawRowBackground(s,rowIndex,y,height,color,dataIndex); } override protected function drawColumnBackground(s:Sprite, columnIndex:int, color:uint, column:DataGridColumn):void { // TODO Auto Generated method stub super.drawColumnBackground(s, columnIndex, color, column); } } }
对列的重写是同样的原理,重写的方法drawColumnBackground(s:Sprite, columnIndex:int, color:uint, column:DataGridColumn)
posted on 2013-02-25 17:38 Neil Li_Gis 阅读(255) 评论(0) 收藏 举报
浙公网安备 33010602011771号