views:

252

answers:

0

Hi,

I have a Flex AdvancedDataGrid which is fed XML like this:

<documents>
 <document>
  <name>Jake</name>
   <skills>
    <skill>Flex</skill>
    <skill>Domino</skill>
    <skill>ASP.NET</skill>
   </skills>
  <document>
 <document>
  <name>Trevor</name>
   <skills>
    <skill>Flex</skill>
    <skill>C++</skill>
    <skill>ASP.NET</skill>
   </skills>
  <document>
</documents>

What I want to do is using a GroupingField to group the people by skill. So that Jake and Trevor both appear under 3 groups/twisties and there are 4 groups in total.

So, one document/row can appear in more than one group. Is this possible? From what I've read I don't think it is.

I've come up with a "hack" which I'm not that happy with. What I've done is changed the XML to this:

<document>
 <name>Jake</name>
 <skills>Flex, Domino, ASP.NET</skills>
<document>

What I then do is run this code when the user chooses to group by skill:

var mygroup:GroupingCollection=new GroupingCollection();
var tmp:XMLListCollection = new XMLListCollection();
//_documents is an XMLListCollection and the dataprovider of the grid!
for each(var doc:XML in _documents){
 var items:Array = doc['skills'].toString().split(', ');
 for each (var skill:String in items){
  tmp.addItem(doc.copy().replace('skills',XML('<skills>'+skill+'</skills>')));
 }
}
mygroup.source = tmp;

So, what I end up with is a new XMLListCollection that has as a row in it for each person's invidivual skills. The code then goes on to group the new collection on the skills field and, hey presto, it works.

I just can't help feeling there must be a better way?

Jake