Flex 自定义DataGrid实现根据条目某一属性值改变背景颜
来源:本站原创|时间:2022-11-25|栏目:Flex|
自定义拓展的DataGrid(as类)代码如下:
package czgh.components { import flash.display.Sprite; import mx.controls.DataGrid; import mx.core.UIComponent; public class OptionalDataGrid extends DataGrid { private var _rowColorFunction:Function; private var _customed:Boolean; private var _customerColor:uint=0; public function OptionalDataGrid() { super(); } override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void { color=0XFFFFFF; if(this._rowColorFunction != null) { if (dataIndex < this.dataProvider.length) { var item:Object=this.dataProvider.getItemAt(dataIndex);//设定颜 color=this._rowColorFunction.call(this, item, color); } } super.drawRowBackground(s, rowIndex, y, height, color, dataIndex); } override protected function drawHeaderBackground(headerBG:UIComponent):void { headerBG.setStyle("borderVisible","false"); } public function set rowColorFunction(rowColorFunction:Function):void { this._rowColorFunction=rowColorFunction; } public function get rowColorFunction():Function { return this._rowColorFunction; } } }
在mxml中实现自定义的datagrid并使用 其rowColorFunction方法
//通过比较每条记录中dataField为act和stand的大小决定该条记录的背景颜 private function setCustomColor(item:Object, color:uint):uint { if (Number(item["act"])<Number(item["stand"])) { return 0x7bbfea; } return color; }
您可能感兴趣的文章
- 01-11flex调用webservice中的自定义类的方法
- 01-11datagrid不可编辑行有关问题的控制方法
- 01-11Flex实现的上传摄像头拍照并将UI保存为图片
- 01-11Flex字体加粗问题只能对英文的字体加粗
- 01-11flex利用webservice上传照片实现代码
- 01-11Flex控制弹出窗口拖动范围示例代码
- 01-11flex内嵌html网页示例代码
- 01-11Flex中在Tree绑定数据后自动展开树节点的方法
- 01-11Flex弹出窗口请求Action函数示例
- 01-11Flex中通过RadioButton进行切换示例代码