您的位置:首页 > 其它

Flex AdvancedDataGrid能够修改某一条背景颜色的继承方法

2009-09-11 17:41 369 查看
继承的新类:

package cn.eu.view
{
import flash.display.Sprite;

import mx.controls.*;
public class UserDataGrid extends AdvancedDataGrid {
private var _rowColor:Function;
public function UserDataGrid(){
super();
}
public function set rowColor(f:Function):void{
this._rowColor = f;
}
override protected function drawRowBackground(s:Sprite,rowIndex:int,y:Number, height:Number, color:uint, dataIndex:int):void{
var dataSource:Object = this.dataProvider;
if(this._rowColor != null && dataSource != null && dataIndex < dataSource.length){
var item:Object = this.dataProvider.getItemAt(dataIndex);
color = this._rowColor.call(this, item,color);
}
super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}
}
}

调用的MXML:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:control="com.qiansoft.view.*">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.CloseEvent;
import mx.controls.Alert;
import mx.events.ListEvent;
[Bindable]
private var sellList:ArrayCollection;
//将上出的数据项背景换个颜色
private function setRowColor(item:Object,color:uint):uint{
if(Boolean(item.save)){
return 0x646565;
}
return color;
}
//双击删除商品信息条目
private function doItemDoubleClick(event:ListEvent):void{
Alert.show("确认删除或恢复操作?","提示",Alert.YES|Alert.NO,this,function(e:CloseEvent):void{doCloseAlert(e,event.rowIndex)});
}
//对话框关闭后的处理事件
private function doCloseAlert(event:CloseEvent,rowIndex:int):void{
if(event.detail == Alert.YES){
var temp:Object = sellList.getItemAt(rowIndex);
temp.save = !Boolean(temp.save);
//替换list数据集中的数据
this.sellList.addItemAt(temp,rowIndex);
this.sellList.removeItemAt(rowIndex);
}
}

private function init():void{
sellList = new ArrayCollection();
sellList.addItem({});
_Grid.dataProvider = sellList;
}
]]>
</mx:Script>
<control:UserDataGrid id="_Grid" designViewDataType="flat" height="100%" width="100%" x="0" y="0" editable="true"
doubleClickEnabled="true"
itemDoubleClick="doItemDoubleClick(event)"
rowColor="setRowColor">
<control:columns>
<mx:AdvancedDataGridColumn headerText="商品编码" dataField="a21" editable="true"/>
<mx:AdvancedDataGridColumn headerText="商品名称" dataField="a2" editable="false"/>
<mx:AdvancedDataGridColumn headerText="库存" dataField="tempa13" editable="false" textAlign="right"/>
<mx:AdvancedDataGridColumn headerText="单位" dataField="a3" editable="false"/>
<mx:AdvancedDataGridColumn headerText="发票类型" dataField="col1" editable="false"/>
<mx:AdvancedDataGridColumn headerText="数量" dataField="a5" editable="true" textAlign="right"/>
<mx:AdvancedDataGridColumn headerText="销价" dataField="xsj" editable="false"/>
<mx:AdvancedDataGridColumn headerText="销价2" dataField="col1" editable="false"/>
<mx:AdvancedDataGridColumn headerText="返点%" dataField="col2" editable="false"/>
<mx:AdvancedDataGridColumn headerText="返点后销价" dataField="col3" editable="false"/>
<mx:AdvancedDataGridColumn headerText="上次销价" dataField="save" editable="false"/>
<mx:AdvancedDataGridColumn headerText="批号" dataField="a27" editable="false"/>
<mx:AdvancedDataGridColumn headerText="效期" dataField="a28" editable="false"/>
</control:columns>
</control:UserDataGrid>
</mx:Application>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: