views:

1142

answers:

2

I'm trying to create a dynamic datagrid in Flex. The data is coming back fine and I can add the column headings. I need to do it this way as the column names are dynamic and coming from a mysql database.

Can anyone help me get the values from re.result.resultSet.results[j].notes into the data fields?

   <mx:Script>
     <![CDATA[

           import mx.rpc.events.FaultEvent;
           import mx.rpc.events.ResultEvent;
       import mx.controls.Alert;
       import mx.controls.dataGridClasses.DataGridColumn; 


            public function faultHandler(event:FaultEvent ):void {
                // The following statements must be inside a function. 

                text.text = event.message.toString();
            }
            public function resultHandler(re:ResultEvent):void {
                // The following statements must be inside a function. 

       text.text = "blah";
       text.text += re.result.resultSet.columnList[0].key.toString();


       for (var i:int = 0; i< re.result.resultSet.columnList.length; i++) {
        text.text += re.result.resultSet.columnList[i].key.toString();

       }
       var cols:Array = new Array();
       var dataProv:Array = new Array();
       for (var j:int = 0; j< re.result.resultSet.columnList.length; j++) {
        text.text += re.result.resultSet.results[j].notes.toString();
        var column:DataGridColumn = new DataGridColumn;
        column.headerText= re.result.resultSet.results[j].label.toString();
        column.dataField = re.result.resultSet.results[j].notes.toString();
        cols.push(column);


            }
            myGrid.columns = cols;


            }



    ]]></mx:Script>
     <mx:TextArea id="text" x="74" y="47" width="551" height="350"/>
     <mx:Button x="647" y="46" label="Button" click ="{myservice.getWorkSheets()}"/>
    <mx:DataGrid id="myGrid" x="74" y="424" width="551"/>

</mx:Application>

thanks,

A: 

There's no dataprovider set for the datagrid. You're defining the columns, but not the row data.

Glenn
A: 

I think you have to validate it after you push the columns.

sample:

myGrid.validateNow();

star_edz