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

继承的新类:

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>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值