출처 : http://www.ihelpers.co.kr/programming/tipntech.php?CMD=view&TYPE=8&KEY=&SC=S&&CC=&PAGE=1&IDX=547
1.데모
2. 소스
MiyaGrid.mxml
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*" creationComplete="initApp()" viewSourceURL="srcview/index.html" fontSize="12"> <mx:Script> <![CDATA[ import mx.controls.dataGridClasses.DataGridColumn; import mx.collections.ArrayCollection; import mx.controls.Alert; [Bindable] private var ArrCol:ArrayCollection = new ArrayCollection(); public function initApp():void{ myGrid.dataProvider = ArrCol; } public function onChangeColumn():void{ // Grid init myGrid.columns = []; ArrCol.removeAll(); var arrCol:Array = new Array(); for(var i:uint = 0; i<chgColumn.value;i++){ var col:DataGridColumn = new DataGridColumn("col"+i); var colRender:ClassFactory = new ClassFactory(LabelRenderer); colRender.properties = {headerText:"컬럼"+i}; col.headerRenderer = colRender; col.setStyle("textAlign","right"); arrCol.push(col); } myGrid.columns = arrCol; for(i=0;i<100;i++){ var colval:Object = new Object; for(var j:uint = 0; j<chgColumn.value;j++){ colval["col"+j] = (i+1)*(j+1); } ArrCol.addItem(colval); } } ]]> </mx:Script> <mx:Component id="HeaderLabelRenderer"> <mx:HBox horizontalAlign="left" verticalAlign="middle"> <mx:Label text="" textIndent="3" width="100%" textAlign="left"/> </mx:HBox> </mx:Component> <mx:DataGrid left="10" right="10" top="70" bottom="10" id="myGrid" fontSize="12"/> <mx:HBox left="10" right="10" top="10" bottom="518"> <mx:Form width="100%"> <mx:FormItem label="컬럼수"> <mx:HSlider id="chgColumn" width="236" minimum="5" maximum="10" snapInterval="1" enabled="true" change="onChangeColumn()"/> </mx:FormItem> </mx:Form> </mx:HBox> </mx:Application> |
LabelRenderer.mxml
Grid HeaderText 값을 동적으로 사용하기 위해 headerText 사용하였습니다.
<?xml version="1.0" encoding="utf-8"?> private var _headerText:String; public function initComp():void { |
3. 참고