I am also building a Tree, and can only sort the top level nodes.  I
have not found an elegant solution to sorting the deeper child nodes,
which leads me to believe I am going to have to walk the tree sorting
as I go, or perhaps sort when a user opens a branch of the tree.

I am perfectly willing to walk the tree, I am just wondering if there
is something I am missing.  I see that the Sort class has a sort
method that takes an array, is there anything like that, that will
take an XMLList?  Seems silly to convert all branches to
XMLListCollections just to sort them (yes, I tried that on
"itemopening", and it crashed firefox randomly) or perhaps I have to
convert my dataprovider to an ArrayCollection.. which seems like a
wrong turn too.. 

any help, hints, or even smart remarks are welcome at this point.

Thanks,
Terry



--- In flexcoders@yahoogroups.com, "durnelln" <[EMAIL PROTECTED]> wrote:
>
> Hi all,
> 
> I am trying to dynamically build and display a sorted tree, i.e. 
> create branches/leaves purely in actionscript.  I *thought* that 
> using XML would make this easy due to its hierarchical nature and 
> Flex's e4x extensions (which should allow me to easily locate nodes 
> in the tree etc without having to code a load of recursion).  An 
> example of the kind of structure I am trying to build looks something 
> like this:
> 
> <group id="1" name="group 1" parent="" displayOrder="1">
>     <group id="1_1" name="group 1_1" parent="1" displayOrder="1">
>         <group id="1_1_1" name="group 1_1_1" parent="1_1" 
> displayOrder="1" />
>     </group>
>     <group id="1_2" name="group 1_2" parent="1" displayOrder="2" />
> </group>
> <group id="2" name="group 2" parent="" displayOrder="2" />
> <group id="3" name="group 3" parent="" displayOrder="3">
>     <group id="3_1" name="group 3_1" parent="3" displayOrder="1" />
> </group>
> 
> I am using an XMLListCollection as my tree data provider as this 
> provides the sorting capabilities I need to retain the sort order as 
> I add new nodes.  As new group objects come in the plan is to turn 
> them into XML and add them to the tree in the appropriate location 
> (based on their parent attribute).  The groups may come in in any 
> order so I make use of the sort ability of the XMLListCollection.
> 
> After going round in circles for a couple of days trying to get it to 
> work, I found the following article on Peter Ent's blog:
> 
> http://weblogs.macromedia.com/pent/archives/2006/10/tree_control_da.cf
> m
> 
> This has proven invaluable (thanks Peter!).  However I am still 
> having problems.  In Peter's example he adds top-level nodes via the 
> XMLListCollection's addItem method but child nodes via the 
> appendChild method of the underlying XML/XMLList object.  Now, while 
> this allows me to build a tree, the child nodes added directly to the 
> XML are not sorted according to the XMLListCollection's sort order - 
> only the top-level nodes are sorted.
> 
> Does anyone know how I can build this tree whilst maintaining the 
> sort order?  I do not want to hard-code any particular sort function 
> as I want the sort field and direction etc. to remain configurable.
> 
> Alternatively, is there any way to add child nodes directly through 
> the XMLListCollection object?  It surprises me that a collection 
> designed for hierarchical XML data doesn't seem to support this (or 
> e4x for that matter).  Why should it be necessary to access the 
> underlying XML data directly to add child nodes (causing the sort 
> order to break)?
> 
> Somebody please help - this is driving me nuts!
> 
> Nick.
>

Reply via email to