views:

169

answers:

1

I am trying to display a list of items in a datagrid from an XMLList.

<Series no="1">
    <file>
        <filenum>1</epnum>
        <prodnum>4V01</prodnum>
        <title>Series #1 - File #1</title>
    </file>
    <file>
        <filenum>2</epnum>
        <prodnum>4V02</prodnum>
        <title>Series #1 - File #2</title>
    </file>
</Series>
<Series no="2">
    <file>
        <filenum>1</epnum>
        <prodnum>4V01</prodnum>
        <title>Series #2 - File #1</title>
    </file>
    <file>
        <filenum>2</epnum>
        <prodnum>4V02</prodnum>
        <title>Series #2 - File #2</title>
    </file>
</Series>

My current code allows me to retrieve every Series into an XMLList and then i have a nesteddatagrid class that allows me to do things like.

<classes:NestedDataGrid width="100%" height="100%" id="gridFiles" dataProvider="{filesList}" >
<classes:columns>
<mx:DataGridColumn headerText="Season" dataField="@no" width="60"/>
<mx:DataGridColumn headerText="Episode" dataField="file.filenum" width="60"/>
<mx:DataGridColumn headerText="Title" dataField="file.title"/>
</classes:columns>
</classes:NestedDataGrid>

However this displays the datagrid with two rows, the first row has 1 in the Series column and then the two files crammed into the second cell in the same row. The second row is the same but has the number 2 in the Series column and the two series #2 files crammed into the cell next to it.

If i do not use the nested data class i can pull the files using Series.file instead and all 4 of the files list correctly, however i do not get the Series number for each...

+1  A: 

With the current structure of the xml, it's easier to represent it with a two column grid - first column being the series number, and second column being another 2 or 3 column DataGrid that displays file details. But if you don't wanna change the structure, the following code is what you need. Note that since dataField property is not set, you have to specify a sortCompareFunction for sorting the grid based on series number - otherwise it might throw exceptions while trying to sort.

<classes:NestedDataGrid width="100%" height="100%" id="gridFiles" 
  dataProvider="{filesList.Series.file}" >
  <classes:columns><!-- classes copy pasted from OP's code. Whats that? -->
    <mx:DataGridColumn headerText="Season" labelFunction="getSeries" width="60"/>
    <mx:DataGridColumn headerText="Episode" dataField="filenum" width="60"/>
    <mx:DataGridColumn headerText="Title" dataField="title"/>
  </classes:columns>
</classes:NestedDataGrid>
private function getSeries(item:Object, col:DataGridColumn):String
{
  return XML(item).parent().@no;
}


UPDATE:

<mx:DataGrid width="100%" height="100%" id="gridFiles" > 
  <mx:columns>
    <mx:DataGridColumn headerText="Season" labelFunction="getSeries" width="60"/>
    <mx:DataGridColumn headerText="Episode" dataField="epnum" width="60"/>
    <mx:DataGridColumn headerText="Title" dataField="title"/>
  </mx:columns>
</mx:DataGrid>

gridFiles.dataProvider = XML(event.result).descendants('episode');
//use the same getSeries function as above
Amarghosh
Thank you for the response, how would you suggest separating the data grids? how would the Series grid know how many cells to fill with the first Series number? I do not really understand the code above, i know how it is supposed to work but i cannot get it to work. I have added the function as a public function into the mx:Script tag.
medoix
Your xml is not well formed. `<filenum>1</epnum>` is wrong, change it to `<filenum>1</filenum>`
Amarghosh
change dataProvider from `filesList.series.file` to `filesList.Series.file` (uppercase Series)
Amarghosh
And what is the `classes:` namespace? Doesn't `columns` belong to `mx`?
Amarghosh
i have seriesList = XML(evt.result).descendants("Series"); Application.application.ManagePage.seriesList = seriesList;in a class function.forget about the classes: namespace i have removed that now. And also the XML is correct i just changed it to make it easier to understand but forgot the ending tag.
medoix
what does `trace(evt.result)` give?
Amarghosh
http://pastebin.org/46365 - please remember i changed the names etc to make it easier so i do know the correct dataprovider names etc.
medoix
http://pastebin.org/46366 - function class file
medoix
http://pastebin.org/46367 - datagrid mxml
medoix
Series == Season and file = episode, right? Now what all do you need in your DataGrid?
Amarghosh
that is correct, in the datagrid i need each episode listed with the season number from the upper nest and then the epnum, title, airdate, and i have a urlRenderer that makes a button for the link.
medoix
check the updated code
Amarghosh
you make that look so simple lol, thank you so much!Should i start a new topic or can i ask the next question here?
medoix
It's a good practice to ask a new question.
Amarghosh