'ItemRenderer 사용예'에 해당되는 글 1건

  1. 2012.04.28 ItemRenderer 사용예
반응형

1. ComboBox ItemRenderer

< ?xml version="1.0" encoding="utf-8"?>
< mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="450" height="370"
verticalScrollPolicy="off" horizontalScrollPolicy="off" backgroundColor="#FFFFFF">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] public var initDG:ArrayCollection = new ArrayCollection([
{no:0, isChecked:"N"},
{no:1, isChecked:"Y"},
{no:2, isChecked:"N"},
{no:3, isChecked:"N"},
{no:4, isChecked:"Y"}]);
]]>
</mx:Script>
<mx:DataGrid id="myGrid" dataProvider="{initDG}" width="450" height="300" editable="false">
<mx:columns>
<mx:DataGridColumn headerText="no" dataField="no" width="150"/>
<mx:DataGridColumn headerText="isChecked" dataField="isChecked" width="150"/>
<mx:DataGridColumn dataField="isChecked" headerText="itemRenderer">
<mx:itemRenderer>
<mx:Component>
<mx:ComboBox selectedIndex="{data.isChecked=='Y'? 0:1}">
<mx:dataProvider>
<mx:Object label="Y" data="Y"/>
<mx:Object label="N" data="N"/>
</mx:dataProvider>
</mx:ComboBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
< /mx:Application>

2. CheckBox ItemRenderer
< ?xml version="1.0" encoding="utf-8"?>
< mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="450" height="370"
verticalScrollPolicy="off" horizontalScrollPolicy="off" backgroundColor="#FFFFFF">
<mx:Style>
global { font-size:12}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] public var initDG:ArrayCollection = new ArrayCollection([
new RendererVO2(0, "N"),
new RendererVO2(1, "Y"),
new RendererVO2(2, "N"),
new RendererVO2(3, "N"),
new RendererVO2(4, "Y")]);
private var flag:Boolean = false;
private function checkAll():void {
if(flag) {
flag = false;
} else {
flag = true;
}
for(var idx:uint=0; idx<initDG.length; idx++) {
initDG[idx] = new RendererVO(idx, flag ? "Y" : "N");
}
}
]]>
</mx:Script>
<mx:DataGrid id="myGrid" dataProvider="{initDG}" width="450" height="150" editable="false">
<mx:columns>
<mx:DataGridColumn headerText="no" dataField="no" width="150"/>
<mx:DataGridColumn headerText="isChecked" dataField="isChecked" width="150"/>
<mx:DataGridColumn dataField="isChecked" headerText="itemRenderer">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox click="changeVO(event)">
<mx:Script>
<![CDATA[
[Bindable] private var rdVO:RendererVO2;
override public function set data(value:Object):void {
rdVO = RendererVO2(value);
if(value.isChecked == "Y") {
this.selected = true;
} else {
this.selected = false;
}
}
private function changeVO(event:Event):void {
trace(event.target.selected ? "Y" : "N");
var parentObj:Object = event.target.parentApplication;
parentObj.initDG[rdVO.no] = new RendererVO2(rdVO.no, event.target.selected ? "Y" : "N");
}
]]>
</mx:Script>
</mx:CheckBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:Button label="전체선택/해제" click="checkAll()"/>
< /mx:Application>

###파일명 RendererVO2.as
package {
public class RendererVO2 {
[Bindable] public var no:Number;
[Bindable] public var isChecked:String;
public function RendererVO2(p_no:Number, p_isChecked:String) {
this.no = p_no;
this.isChecked = p_isChecked;
}
}
Posted by 1010