DataGrid的行渲染

1 配置渲染器的方式


<mx:DataGridColumn headerStyleName="DISPVALUE" dataField="DISPVALUE" editable="false" fontSize="12" textAlign="left" paddingLeft="5">
<mx:itemRenderer>
<fx:Component>
<local:ItemStyle>
</local:ItemStyle>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>



ItemStyle

public class ItemStyle extends Label
{
/**
* 构造函数
*/
public function ItemStyle() {
super();
}

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(data["POINT_X"]==0||data["POINT_X"]==null){
this.setStyle('color', 0xDD0000);
}else
this.setStyle("color",0x000000);
}

}// end of class
}



2 编码渲染器的方式添加


//必须要实现IFactory接口
public class CellColorIFactory implements IFactory
{
//回调方法
private var _cellColorFunction:Function ;

public function CellColorIFactory(f:Function){
super();
this._cellColorFunction = f;
}

public function newInstance():*{
//实例化渲染器,实现具体功能
return new CellColorItemRenderer(_cellColorFunction);
}
}





public class CellColorItemRenderer extends DataGridItemRenderer
{
//传递回调函数
private var _cellColorFunction:Function;

private var _value:Object;
public function CellColorItemRenderer(f:Function)
{
super();
this._cellColorFunction=f;
}
override public function set data(value:Object):void
{
if (value != null)
{
var data:XML=XML(value);
_value=value;
//调用父类的public function get listData():BaseListData
var dataField:String=DataGridListData(listData).dataField;
while (dataField.indexOf("@") != -1)
dataField=dataField.replace("@", "");
//改变颜色;两个参数,dataField表示数据列(名称),data表示一行数据
setStyle("color", this._cellColorFunction.call(this, dataField, value));
}
}
override public function get data():Object
{
return _value;
}
}





var itemRender:IFactory = new CellColorIFactory(cellColor);
dataColumn.itemRenderer=itemRender;

private function cellColor(dataField:String,data:Object):uint{
//设置前两页显示颜色
//设置默认显示颜色
if(!isNaN(data.x) && !isNaN(data.y)){
return 0x000000;
}else{
return 0xDD0000;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值