PDA

View Full Version : Datagrid question


rattleheadmegafan
08-21-2009, 10:46 PM
I have an XML structure which is like this:


<details>
<personal>
<name>name</name>
<phone>1111111111</phone>
</personal>
<tag1>
<tag2>eee</tag2>
<tag3>ffff</tag3>
<rtag1>
<rtag2>aa</rtag2>
<rtag3>bb</rtag3>
</rtag1>
<rtag1>
<rtag2>cc</rtag2>
<rtag3>dd</rtag3>
</rtag1>
</tag1>
</details>


Now I want to be able to display the following in a datagrid,
name, phone, tag2, tag3 and multiple rtag2 and rtag3's

How do I do it?

Is there a solution, an alternate solution?

TIA!

camden_kid
08-24-2009, 05:39 PM
http://livedocs.adobe.com/flex/3/langref/mx/controls/DataGrid.html#includeExamplesSummary

rattleheadmegafan
08-26-2009, 04:17 AM
Thanks Camden kid, that didn't help at all.

wvxvw
08-26-2009, 06:17 AM
Erm... maybe use Tree or AdvancedDataGrid (this is a component that isn't a part of free SDK)? Becuase DataGrid is intended for display of 2D tables... I believe you can also make a special item-renderer that will display the data you need in some more appropriate way, but I would really consider using another component or organizing your data differently.

rattleheadmegafan
08-26-2009, 03:03 PM
Thanks wvxvw!

amarghosh
08-29-2009, 08:34 AM
i think labelFunction property of DataGridColumn is what u need....
and u can use a List as the itemRenderer for the column displaying rtag2 etc...

amarghosh
08-29-2009, 11:30 AM
i am not able to post the code here... Has anyone else had this problem?

amarghosh
08-29-2009, 11:33 AM
<mx:DataGrid dataProvider="{list}">
<mx:columns>
<mx:DataGridColumn headerText="name" labelFunction="dataFunctionName"/>
<mx:DataGridColumn headerText="phone" labelFunction="dataFunctionPhone"/>
<mx:DataGridColumn headerText="tag2" labelFunction="dataFunctionTag2"/>
<mx:DataGridColumn headerText="tag3" labelFunction="dataFunctionTag3"/>
<mx:DataGridColumn headerText="rtag2">
<mx:itemRenderer>
<mx:Component>
<mx:List rowCount="{data.tag1.rtag1.rtag2.length()}"
dataProvider="{data.tag1.rtag1.rtag2}"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>

amarghosh
08-29-2009, 11:34 AM
public function dataFunctionName(item:Object, column:DataGridColumn):String
{
return item.personal.name;
}
public function dataFunctionPhone(item:Object, column:DataGridColumn):String
{
return item.personal.phone;
}
public function dataFunctionTag2(item:Object, column:DataGridColumn):String
{
return item.tag1.tag2;
}
public function dataFunctionTag3(item:Object, column:DataGridColumn):String
{
return item.tag1.tag3;
}

EDIT: Apparently the issue was related to the size of the post... was trying to post this AS code and the mxml in the previous post together with no luck.

rattleheadmegafan
08-29-2009, 11:47 PM
Thanks Amar, I will try that out.

camden_kid
09-01-2009, 01:29 PM
How does that not help you?

It gives an example of XML data used as the dataProvider of a DataGrid.

rattleheadmegafan
09-01-2009, 05:41 PM
Use the link you gave me and plug in the XML which I posted and you'll know why it did NOT help me. Did you even read the question in the first place? Read the other responses and you'll know if you still don't understand.

Peter Cowling
09-01-2009, 06:50 PM
Use the link you gave me and plug in the XML which I posted and you'll know why it did NOT help me. Did you even read the question in the first place? Read the other responses and you'll know if you still don't understand.

You can ask a question, get an answer, and help one or more people along the way :)


How does that not help you?

It gives an example of XML data used as the dataProvider of a DataGrid.


The hierarchical nature of the xml posted means it differs from the example given in the provided link. Basically, datagrid does not naturally look to fit this sort of xml into seperate columns, so you either have to work the data into it, or re-work the data in a way that it understands. amarghosh gives an example of the latter approach.

Grouping
Although not a direct requirement, people with similar needs may find value in grouping this sort of data; a reasonable starter guide on this subject can be found in this livedocs post on the subject (http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_06.html).

camden_kid
09-01-2009, 08:43 PM
I misunderstood the original question.

The solution's something I will def. use in the future.

Cheers.

rattleheadmegafan
09-01-2009, 09:16 PM
Sorry if I sounded rude and thanks for trying to help me.

camden_kid
09-01-2009, 10:14 PM
No, you weren't rude. You just, quite rightly, made me look at the question and follow-up answers more closely. Which is what is what I should have done in the first place.