Un petit bout de code pour montrer comment ajouter une colonne dynamiquement sur un composant datagrid
- <?xml version="1.0" encoding="utf-8"?>
- <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
- <mx:Script>
- <![CDATA[
- import mx.controls.dataGridClasses.DataGridColumn;
- private function init():void{
- trace (’init’);
- }
- private function addCol():void{
- var tbCol:Array = myData.columns;
- var newCol:DataGridColumn = new DataGridColumn();
- newCol.headerText = "pipo";
- newCol.dataField = "pipo";
- newCol.width = 60;
- newCol.visible = true;
- myData.width = myData.width + newCol.width;
- tbCol.push(newCol);
- myData.columns = tbCol;
- }
- ]]>
- </mx:Script>
- <mx:DataGrid x="75" y="81" id="myData">
- <mx:columns>
- <mx:DataGridColumn headerText="Column 1" dataField="col1"/>
- <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
- <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
- </mx:columns>
- </mx:DataGrid>
- <mx:Button x="84" y="231" label="Button" click="addCol()"/>
- </mx:WindowedApplication>