Groups | Blog | Home
all groups > flash data integration > march 2005 >

flash data integration : Use array/variable data to populate column information for DataGrid


js_theywill
3/5/2005 6:37:06 AM
I have an array of columns, column, that is dynamically created, and then rows
of data for each column, column.data[x]. I can pass data to a DataGrid as
follows.
myGrid.addItem({column1:'ThisDataPoint',column2:'ThatDataPoint',column3:'TheOthe
rDataPoint'}); However, what's the syntax to dynamically populate the addItem
method using my arrays, realizing that I have to do a nested loop through each
row, each column and I don't have any idea how many elements are in each array,
while scripting the code? Thanks for any suggestions. James
js_theywill
3/18/2005 4:25:59 PM
It appears that the DataGrid MUST receive data as an array of rows with
distinct column names, rather than an array of rows with an array of columns.
Please feel free to correct me, if I'm wrong. As such, I had to convert my XML
data, which used both an array of rows AND an array of columns so that the
number of columns could be variable, into an array of objects. // Format and
load data into grid. var thisData:Array = new Array(); // Loop through rows.
for (j=0; j<tableRows.length; j++) { tableRows.selectedIndex = j;
thisData[j] = new Object; // Loop through columns. for (k=0;
k<tableRowData.length; k++) { thisData[j]['column'+k] =
tableRowData.items[k]; } } thisGrid.dataProvider = thisData; The line
thisData[j]['column'+k] = tableRowData.items[k]; is the one that assigns the
object within the array dynamically, such that one element might be
thisData[0].column3 = 'some text'. The code above allows me to have one
DataGrid that is dynamically populated using action script and a few DataSets
and DataHolders with any number of rows or columns, without having to
specifically label the columns within the XML. A snippet from the source XML
is as follows. Note that the real XML file includes an array of parent nodes.
<rows> <row> <col>Machines</col> <col>32</col> </row> <row>
<col>Employees</col> <col>55</col> </row> </rows> Thanks, James
AddThis Social Bookmark Button