Flex 迷你教程 — 动态改变DataGird行的颜色
2009-04-21 11:47
387 查看
实现DataGird行颜色的改变不难,网上也有很多类似的教程,不过有的太罗嗦,有的说的又太简单,我稍微折中了一下。
首先继承DataGrid做一点简单的扩展。扩展的目的是:
添加一个rowColorFunction,根据当前行的值设置行的颜色,用法与labelFunction一样。
覆写drawRowBackground, 让其能用rowColorFunction返回的颜色设置当前行。
附件的RowColorDataGrid.as 是国外一个家伙写的,我没改(实在没什么可改的了),只添加了注释帮助大家理解。下面是一个简单的Demo, 将check box钩中的行高亮显示:
RowColorDataGrid.aspackage
{
import flash.display.Sprite;
import mx.collections.ArrayCollection;
import mx.controls.DataGrid;
public class RowColorDataGrid extends DataGrid
{
//用于设置颜色,参数: 当前item, rowIndex, dataIndex, 当前color
public var rowColorFunction:Function;
//覆写drawRowBackground,目的是根据rowColorFunction返回颜色设置当前行
override protected function drawRowBackground(
s:Sprite, rowIndex:int, y:Number, height:Number,
color:uint, dataIndex:int):void
{
if(rowColorFunction != null)
{
//从dataProvider中获取当前item
var item:Object;
if(dataIndex < dataProvider.length)
{
item = dataProvider[dataIndex];
}
if(item)
{ //如果当前item存在,从rowColorFunction中获取行的颜色
color = rowColorFunction(item, rowIndex, dataIndex, color);
}
}
//调用父类方法设置当前行颜色
super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}
}
}
原文:http://www.flextheworld.com/2009/02/flex-datagrid-row-color.html
首先继承DataGrid做一点简单的扩展。扩展的目的是:
添加一个rowColorFunction,根据当前行的值设置行的颜色,用法与labelFunction一样。
覆写drawRowBackground, 让其能用rowColorFunction返回的颜色设置当前行。
附件的RowColorDataGrid.as 是国外一个家伙写的,我没改(实在没什么可改的了),只添加了注释帮助大家理解。下面是一个简单的Demo, 将check box钩中的行高亮显示:
RowColorDataGrid.aspackage
{
import flash.display.Sprite;
import mx.collections.ArrayCollection;
import mx.controls.DataGrid;
public class RowColorDataGrid extends DataGrid
{
//用于设置颜色,参数: 当前item, rowIndex, dataIndex, 当前color
public var rowColorFunction:Function;
//覆写drawRowBackground,目的是根据rowColorFunction返回颜色设置当前行
override protected function drawRowBackground(
s:Sprite, rowIndex:int, y:Number, height:Number,
color:uint, dataIndex:int):void
{
if(rowColorFunction != null)
{
//从dataProvider中获取当前item
var item:Object;
if(dataIndex < dataProvider.length)
{
item = dataProvider[dataIndex];
}
if(item)
{ //如果当前item存在,从rowColorFunction中获取行的颜色
color = rowColorFunction(item, rowIndex, dataIndex, color);
}
}
//调用父类方法设置当前行颜色
super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}
}
}
原文:http://www.flextheworld.com/2009/02/flex-datagrid-row-color.html
相关文章推荐
- DataGirdView如何改变选中的CheckBox行的背景颜色:
- Flex个人使用总结:ClassFactory,动态为DataGird添加渲染列
- flex 自定义css样式来改变button的颜色 flex 教程 flex培训 flex源码 flex实例
- flex datagird 动态刷新单元格数据
- 动态改变Drawable中我们自定义背景的颜色并设置颜色以16进制进行设置
- datagirdView 设定指定字母的颜色,等于H字母的为浅红色
- flex spark datagird 样式
- Android自定义TextView实心圆角颜色背景(动态改变圆角背景颜色)
- .NET中动态生成的表格,当鼠标经过tr时改变tr当前颜色,当鼠标移开恢复原来的颜色
- Photoshop入门教程 单改变眼睛的颜色
- silverlight datagird动态绑定
- Android动态改变TextView字体颜色
- android动态改变textView字体的颜色
- Flex 迷你教程 — DataGrid, 拖拽数据到chart中显示
- android 动态改变SVG的颜色
- UITableViewCell动态的改变cell的状态变化,比如文字颜色?
- flex通过httpService获取远程XML数据,并显示到DATAGIRD上
- Flex DataGird导出到excel