Flex 自定义DataGrid实现根据条目某一属性值改变背景颜色

栏目: 编程语言 · 发布时间: 7年前

内容简介:本节主要介绍了Flex DataGrid根据条目某一属性值改变背景颜色,此DataGrid为自定义拓展的,需要的朋友可以参考下

自定义拓展的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; 
}

以上所述就是小编给大家介绍的《Flex 自定义DataGrid实现根据条目某一属性值改变背景颜色》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

代码里的世界观——通往架构师之路

代码里的世界观——通往架构师之路

余叶 / 人民邮电出版社 / 2018-11 / 59.00元

本书分为两大部分,第一部分讲述程序员在编写程序和组织代码时遇到的很多通用概念和共同问题,比如程序里的基本元素,如何面向对象,如何面向抽象编程,什么是耦合,如何进行单元测试等。第二部分讲述程序员在编写代码时都会遇到的思考和选择,比如程序员的两种工作模式,如何坚持技术成长,程序员的组织生产方法,程序员的职业生涯规划等。一起来看看 《代码里的世界观——通往架构师之路》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具