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

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

内容简介:本节主要介绍了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实现根据条目某一属性值改变背景颜色》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95

Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具