2
votes

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,

2
Can you explain a little more.I think this code should work and add column at runtime what is the problem you are facing - Rahul Garg
The column headings appear for the data grid but all the cells are empty. - codecowboy
Hey sorry for the confusion I see what you are trying to do now, and my code was doing it the other way. I hope at least the dataField bit clears something up. - ryanday
well, it might if you hadnt deleted it..... - codecowboy

2 Answers

1
votes

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

-1
votes

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

sample:

myGrid.validateNow();