For some XML:

<people>
                <person>
                                <firstName>Alex</firstName>
                                <lastName>Haruie</lastName>
                </person>
...

It would be faster to have a class:

Class Person
{
                Public var firstName:String;
                Public var lastName:String;
}

and loop through the XML once, making an array of Persons, and using 
ArrayCollection instead of XMLListCollection and doing the sorting and copying 
via toArray(). XML property access is orders of magnitude slower than class 
instance property access and the number of accesses required in sorting are 
significant.  This strategy will have the advantage of fully divesting itself 
from the original XML.  XMLLists have some ties back to the original XML and 
some manipulations might cause change notifications and maybe some of the 
problems you're seeing.

Whenever you need the XML again, maybe when reporting back to the server, you 
create the XML from the array of class instances.

Alex Harui
Flex SDK Developer
Adobe Systems Inc.<http://www.adobe.com/>
Blog: http://blogs.adobe.com/aharui

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of chris.cobb40
Sent: Tuesday, April 07, 2009 9:31 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: DataGrid Column Sort Prevents Drag From Updating 
DataProvider


I'm sorry I don't understand what you mean by that - could you explain a bit 
more please.

Sorry for being thick and thanks again.

Chris

--- In flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>, Alex 
Harui <aha...@...> wrote:
>
> It occurs to me that this might be easier and faster if you convert the XML 
> to class instances and only go back to XML at the last minute. Try doing that.
>
> Alex Harui
> Flex SDK Developer
> Adobe Systems Inc.<http://www.adobe.com/>
> Blog: http://blogs.adobe.com/aharui
>
> From: flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com> 
> [mailto:flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>] On 
> Behalf Of chris.cobb40
> Sent: Tuesday, April 07, 2009 1:55 AM
> To: flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>
> Subject: [flexcoders] Re: DataGrid Column Sort Prevents Drag From Updating 
> DataProvider
>
>
> Hi Alex
>
> I gave it a try and I can see what you are getting at but I would be grateful 
> for a bit more help.
>
> What I want to do is to -
>
> 1. Make copy of the XMLListCollection dataprovider in an array by using 
> toArray();
>
> 2. Remove the sort for XMLListCollection dataprovider.
>
> 3. Copy the data back from the array into the XMLListCollection.
>
> I tried the following(InitiativeList is the XMLListCollection):
>
> var iniCopy:Array = InitiativeList.toArray();
> var iniXMLCopy:XMLListCollection = new XMLListCollection();
>
> InitiativeList.sort = null;
>
> for (var i:int = 0; i < iniCopy.length; i++) {
> iniXMLCopy.addItemAt(iniCopy[i],i);
> }
>
> InitiativeList = new XMLListCollection(XMLList(iniXMLCopy.toXMLString()));
>
> InitiativeList.refresh();
>
> It sort of works but for some reason the first drag I do does not work but 
> then subsequent ones do.
>
> Could you give me an idea of where I am going wrong - I guess there is a 
> better way than the long winded method I have used anyway.
>
> Thanks a lot.
>
> Chris
>
> --- In 
> flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com>,
>  "chris.cobb40" <chris.cobb40@> wrote:
> >
> > Hi Alex
> >
> > Thanks for that - I understand what you meant in your reply to the other 
> > guy now - just me being slow.
> >
> > I will give it a try.
> >
> > Chris
> >
> > --- In 
> > flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com>,
> >  Alex Harui <aharui@> wrote:
> > >
> > > A collection is either sorted or not, and if there is a sort, it won't 
> > > let you re-order. One way to allow re-ordering is, after a Sort (and the 
> > > CollectionEvent.REFRESH event), copy the sorted results into an unsorted 
> > > collection using toArray on the sorted collection.
> > >
> > > Alex Harui
> > > Flex SDK Developer
> > > Adobe Systems Inc.<http://www.adobe.com/>
> > > Blog: http://blogs.adobe.com/aharui
> > >
> > > From: 
> > > flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com>
> > >  
> > > [mailto:flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com>]
> > >  On Behalf Of chris.cobb40
> > > Sent: Monday, April 06, 2009 10:23 AM
> > > To: 
> > > flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com>
> > > Subject: [flexcoders] DataGrid Column Sort Prevents Drag From Updating 
> > > DataProvider
> > >
> > >
> > > Hi
> > >
> > > I think I've seen this commented on before on flexcoders so sorry for the 
> > > duplication.
> > >
> > > In the reply the person who asked the question was told to turn off the 
> > > Column Sort and that would do it but won't this reset the sort order back 
> > > to default before allowing the drag ?
> > >
> > > I want to cater for the situation where the user might want to sort the 
> > > DataGrid into reverse alphabetical order and then just drag the resulting 
> > > first row to be the second one.
> > >
> > > Maybe I'm using the wrong method of turning off the column sort - I set 
> > > the sort property of the ListColection DataProvider for the DataGrid to 
> > > null and then refresh ?
> > >
> > > Any sugegstions please ?
> > >
> > > Thanks
> > >
> > > Chris
> > >
> >
>

Reply via email to