首先写自定义类 继承自DataGrid package BaseUI { import flash.display.Sprite; import mx.controls.DataGrid; public class CustomerDataGrid extends DataGrid { private var _rowColorFunction:Function; //用于在外部能通过指定一个方法 去实现改变列的背景色 public function CustomerDataGrid() { super(); } public function set rowColorFunction(f:Function):void { this._rowColorFunction = f; } public function get rowColorFunction():Function { return this._rowColorFunction; } //复写该方法 override protected function drawRowBackground(s:Sprite,rowIndex:int,y:Number, height:Number, color:uint, dataIndex:int):void { if( this.rowColorFunction != null ){ if( dataIndex <columns><datagridcolumn datafield="waid" headertext="预警编号" visible="false"></datagridcolumn><datagridcolumn datafield="wanm" headertext="预警名称"></datagridcolumn><datagridcolumn datafield="stcd" headertext="测站编号" visible="false"></datagridcolumn><datagridcolumn datafield="STNM" headertext="测站名称"></datagridcolumn><datagridcolumn datafield="stid" headertext="状态" labelfunction="stateFunction"></datagridcolumn><datagridcolumn datafield="" headertext="操作" itemrenderer="view.ssjk.ui.SsjkRainItemRender"></datagridcolumn></columns> //改变颜色方法 private function colorFunction(item:Object, color:uint):uint { switch(item.stid) { case 0: break; case 1: color=0xF10026; break; case 2: color=0x26972d; break; case 3: color=0xFFDF00; break; case 4: color=0xFFDF00; break; case 5: color=0xFFDF00; break; case 6: color=0xFFDF00; break; case 7: color=0xFFDF00; break; } return color; }
改变Flex DataGrid 行的背景色
最新推荐文章于 2013-10-22 16:17:21 发布