Flex修改DataGrid行颜色以及按行值设置行颜色
来源:互联网 发布:手机对讲机软件好用吗 编辑:程序博客网 时间:2024/06/05 01:03
本文转载自:http://gis-conquer.blog.sohu.com/159939428.html
发现Flex背景色让行的颜色改变是有些不妥之处,就是在行数较少没有填满当前的DataGrid控件时,就连空行也变了颜色。以下是不本人自定义的一个控件,通过重写drawRowBackground,对绘制的dataIndex进行判断,可以完成设置行的颜色的设置和按值设置指定的颜色:
package widgets.Utility.Control
{
import flash.display.Sprite;
import mx.controls.*;
public class DataGridColored extends DataGrid
{
private var _rowColorFunction:Function;
private var _customed:Boolean;//是否自定义颜色设置
private var _customerColor:uint=0;//自定义颜色
public function DataGridColored()
{
super();
}
public function set rowColorFunction(rowColorFunction:Function):void
{
this._rowColorFunction=rowColorFunction;
}
public function get rowColorFunction():Function
{
return this._rowColorFunction;
}
public function set customed(customed:Boolean):void
{
_customed=customed;
}
public function get customed():Boolean
{
return _customed;
}
public function set customerColor(customerColor:uint):void
{
_customerColor=customerColor;
}
public function get customerColor():uint
{
return _customerColor;
}
override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void
{
if (_customed==true)
{
if (this._rowColorFunction != null)
{
if (dataIndex < this.dataProvider.length)
{
var item:Object=this.dataProvider.getItemAt(dataIndex);//按指定行进行颜色设置
color=this._rowColorFunction.call(this, item, color);
}
}
else
{
if (this._customerColor!=0)
{
if (dataIndex < this.dataProvider.length)
{
color=this._customerColor;
}
}
}
}
super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}
}
}
使用时注意两个参数:
customed:Boolean;//是否自定义颜色设置
customerColor:uint=0;//自定义颜色
如:
this.dataGrid.customed=true;
this.dataGrid.customerColor=0x7fceff;
也可直接在MXML进行设置
按值设置指定的颜色需要指定外部回调函数rowColorFunction
如:
在MXML设置:rowColorFunction="rowColorFunction"
下面将column1列值为gisconquer的行颜色设置为0xbeff8e
private function rowColorFunction(item:Object, color:uint):uint
{
if (item['column1'] == "gisconquer") //将column1列值为gisconquer的行颜色设置为0xbeff8e
{
return 0xbeff8e;
}
return color;
}
- Flex修改DataGrid行颜色以及按行值设置行颜色
- Flex设置DataGrid单元格颜色以及表头背景颜色渐变
- Flex DataGrid行自定义颜色
- dataGrid中动态设置行颜色
- Flex修改datagrid 标题颜色(引入CSS样式修改)
- DataGrid 行改变颜色
- Flex datagrid/advancedatagrid按条件显示行的背景颜色
- Flex datagrid/advancedatagrid按条件显示行的背景颜色
- 修改DataGrid选中颜色
- DataGrid背景颜色设置
- Flex DataGrid设置不同行的渲染颜色
- Flex 四种方式设置dataGrid表头颜色
- Flex 四种方式设置dataGrid表头颜色
- FLEX DataGrid背景颜色调试
- Flex中如何通过selectionColor和selectionDisabledColor样式设置DataGrid的行选中与无效时颜色的例子
- flex DataGrid根据数据动态显示行颜色(重写DataGrid组件)
- WPF 设置DataGrid 鼠标移动改变行颜色样式
- easyui 设置dataGrid选中行的背景颜色
- JAVA 代码基础规范汇总
- ABAP制作密码输入框
- IE6下png透明问题解决的最佳方案
- 刚学了构造函数,编个程序(两个数的加减乘除运算)
- Android开发之OpenGL+ES教程
- Flex修改DataGrid行颜色以及按行值设置行颜色
- 单列模式
- 一致性 hash 算法( consistent hashing )
- SAP文件夹存在的判断与创建
- 算法入门之串的顺序存储表示
- 【Android】View类详解 (游戏开发必备)
- word2007中鼠标不能定位问题
- BoneCP(马勒・格・彼得)
- memcached分布式hash策略测试