DataGrid 背景颜色的控制(二)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
<![CDATA[
import mx.controls.Alert;
]]>
</mx:Script>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
]]>
</mx:Script>

<mx:Script>
<![CDATA[
import mx.controls.Button;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.collections.ArrayCollection;
[Bindable]
private var dpADG:ArrayCollection = new ArrayCollection([
{Artist:'Pavement', Album:'Slanted and Enchanted', Price:12.99},
{Artist:'Pavement', Album:'Brighten the Corners', Price:13.99},
{Artist:'Saner', Album:'A Child Once', Price:14.99},
{Artist:'Saner', Album:'Helium Wings', Price:12.99},
{Artist:'The Doors', Album:'The Doors', Price:10.99},
{Artist:'The Doors', Album:'Morrison Hotel', Price:12.99},
{Artist:'Grateful Dead', Album:'American Beauty', Price:11.99},
{Artist:'Grateful Dead', Album:'In the Dark', Price:17.99},
{Artist:'Grateful Dead', Album:'Shakedown Street', Price:13.99},
{Artist:'The Doors', Album:'Strange Days', Price:12.99},
{Artist:'The Doors', Album:'The Best of the Doors', Price:10.99}
]);



protected var artistName:String="Saner";
protected var price:Number=13;
// Event handler to set the selected artist's name
// based on the selected Button control.
public function setArtistName(event:Event):void
{
artistName=Button(event.currentTarget).label;
// Refresh row display.
myADG.invalidateList();
}
// Callback function that hightlights in red
// all rows for the selected artist.
public function myStyleFunc(data:Object,
col:AdvancedDataGridColumn):Object
{
if (data["Artist"] == artistName)
return {color:0xFF0000};
// Return null if the Artist name does not match.
return null;
}

public function myColStyleFunc(data:Object,
col:AdvancedDataGridColumn):Object
{
if(data["Price"] <= price)
return {color:0x00FF00};

return null;
}
public function myColStyleFunc2(data:Object,
col:AdvancedDataGridColumn):Object
{

if(data["Artist"]==artistName)
return {color:0xFFFF00};
return null;
}

public function test():void{
Alert.show("test");
}


]]>
</mx:Script>

<mx:AdvancedDataGrid id="myADG" width="100%" height="100%" dataProvider="{dpADG}" >
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Artist" styleFunction="myColStyleFunc2" />
<mx:AdvancedDataGridColumn dataField="Album" />
<mx:AdvancedDataGridColumn dataField="Price" styleFunction="myColStyleFunc"/>
<mx:AdvancedDataGridColumn textAlign="center" headerText="删除">
<mx:itemRenderer>
<mx:Component>
<!-- The second parameter of the Event constructor (true) indicates that the event should "bubble".
This allows us to listen for the deleteRow event on the DataGrid (see init function) -->
<mx:Button icon="@Embed('icon_plus.png')" click="dispatchEvent(new Event('deleteRow', true));" />
</mx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>

</mx:columns>
</mx:AdvancedDataGrid>
<mx:HBox>
<mx:Button label="Pavement" click="setArtistName(event);"/>
<mx:Button label="Saner" click="setArtistName(event);"/>
<mx:Button label="The Doors" click="setArtistName(event);"/>
</mx:HBox>

</mx:Application>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值