try this, my old code,
<mx:DataGrid id="dg3" width="100%" dataProvider="{orgXML.location}"
creationComplete="dg3.columns =
generateCols(orgXML.location, false)" rowHeight="20"
click="selectStore(event)" updateComplete="d3build()"
allowMultipleSelection="true" variableRowHeight="true" />
private function generateCols(input:XMLList, useAttributes:Boolean =
false):Array
{
var e1:XML = input[0];
var columns:Array = [];
var children:XMLList ;
if (useAttributes)
{
children = e1.attributes();
}
else
{
children = e1.children();
}
for each(var child:XML in children)
{
var col:DataGridColumn = new DataGridColumn();
col.dataField = useAttributes ? "@" + child.name() : child.name();
var fieldName:String = child.name();
col.headerText = fieldName.charAt(0).toUpperCase() +
fieldName.substr(1);
// create itemrenderer
if(col.headerText == "Survey")
col.itemRenderer = new ClassFactory(imageCR);
else if (col.headerText == "Percent" )
col.itemRenderer = new ClassFactory(percentCR);
var tempObj:Object = new Object();
tempObj = {
label : col.headerText
}
cList.addItem(tempObj);
columns.push(col);
}
return columns;
}
Willy
617-606-3437
----------------------------------------------------------------------
6 X 9 = 42
Q: How do you spell "google"?
A: Why don't you google it?
----------------------------------------------------------------------
On Thu, Apr 23, 2009 at 9:05 AM, blkmajk111 <[email protected]>wrote:
>
>
> Hey All,
>
> I'm having an issue that I was hoping someone can help me out with.
>
> I need to populate a datagrid based on XML being returned to Flex. The
> structure of the XML is as follows:
>
> "<root>
> <lab id="2" title="Chemical Materials">
> <assignment assignmentid="2" name="s2 s2" grade="B"/>
> <assignment assignmentid="4" name="s1 s1" grade="C"/>
> <assignment assignmentid="6" name="John Smith" grade="B"/>
> </lab>
> <lab id="8" title="BioChem">
> <assignment assignmentid="3" name="s2 s2" grade="F"/>
> <assignment assignmentid="5" name="John Smith" grade="D"/>
> </lab>
> </root>"
>
> When this XML gets returned to Flex I need to throw it into a Datagrid for
> diaplay. The catch is there can be any number of columns in the datagrid
> becasue the assignments can be of different quantities.
>
> Here is the code that I am using to make the grid:
>
> "private function getGradebookSectionDb(event:ResultEvent):void{
> var gradebookBySection:XMLList = event.result.lab;
>
> var cols:Array=new Array;
>
> for (var i:int=0;i<gradebookBySection.length();i++){
> var col:DataGridColumn=new DataGridColumn();
> col.headertext=gradebookbysection[[email protected]();
> col.dataField=gradebookBySection[i].children()[email protected]();
> cols.push(col);
> gradebookDatagrid.columns=cols;
> gradebookDatagrid.visible=true;
> }"
>
> When I do this, the columns get created from the XML very nicely with the
> headers displaying correctly but there is no data showing up in the columns.
> I would like to get one of the attribute values in each column but for some
> reason nothing comes up. When I do a trace on the "col.datafield" I get the
> right information coming back in the trace but nothing shows up in the
> column.
>
> I would have just assigned the XML as a datapovider to the datagrid but as
> the amount of assignments returned can change, I saw this as my only option.
>
> Can anyone help me with this?
>
> Thanks!
>
>
>