There is a nice example in the Sort class documentation: http://livedocs.adobe.com/flex/3/langref/mx/collections/Sort.html#compareFunction
--- In flexcoders@yahoogroups.com, crazy developer <geekydevelo...@...> wrote: > > Hi Thanks for replying > What does we mean by custom sort compare function, Can we provide any > examples of both sort and sort compare functions or little more details > about what and how does we do that? > Thanks much fro your help > > > > On Thu, Mar 5, 2009 at 11:24 AM, Alex Harui <aha...@...> wrote: > > > If you have a labelfunction, you'll probably need a custom sortcompare > > function > > > > > > > > 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 *anuj181 > > *Sent:* Wednesday, March 04, 2009 3:51 PM > > *To:* flexcoders@yahoogroups.com > > *Subject:* [flexcoders] Problem in sorting XMLList collection as a > > dataProvider for the list > > > > > > > > Hi Guys > > > > I am trying to sort the xmllist collection which is the dataprovider for > > the list. As the implementation of name-value pairs, i am displaying the > > entries in form of string in List and would like to sort all the data > > displayed in the List alphabetically, I am making a call through amfphp call > > to grab data from backend and populate XMLListCollection but now I need to > > sort the data in the list. Below is the code,Can anyone please help me where > > I am messing things up. Also please let me know if there is any question > > regarding the code and if there is better way of doing it. > > > > Thanks > > > > /******************CODE************/ > > > > <mx:RemoteObject id="amfSetup" source="Setup" destination="amfphp"> > > <mx:method name="getList" result="getListHandler(event);" > > fault="getListFault(event);"/> > > </mx:RemoteObject> > > > > [Bindable] private var entriesXmlListFull:XMLList; > > [Bindable] private var entriesXmlCollection:XMLListCollection; > > > > > > public function getListHandler(event:ResultEvent):void > > { > > > > entriesXmlListFull = XML(event.result).device; > > populateEntries(); > > } > > private function getListFault(event:FaultEvent):void > > { > > Alert.Show("Error retreiving Data"); > > } > > > > //Displaying names need to be displayed in the List box > > private function entriesLabelFunc(item:Object):String > > { > > var xmlItem:XML = item as XML; > > > > return xmlItem..attribute.(@name=="friendlyname"); > > } > > > > //Populating List with XML Objects > > private function populateEntries():void > > { > > entriesXmlCollection = new XMLListCollection(); > > > > for each(var item:XML in entriesXmlListFull) > > { > > > > var friendlyName:String = item..attribute.(@name=="friendlyname"); > > //Only add camera type > > if ( !recordValue && hasFriendlyName && (itemType.toUpperCase() == > > "CAMERA") ) > > { > > entriesXmlCollection.addItem(item); > > } > > } > > > > //Calling Sort on XMLList collection > > entriesXmlCollection.sort = sortList; > > entriesXmlCollection.refresh(); > > > > > > } > > > > > > <mx:Sort id="sortList"> > > <mx:fields> > > <mx:SortField name="*" caseInsensitive="true" /> > > </mx:fields> > > </mx:Sort> > > > > <mx:List id="listData" dataProvider="{entriesXmlCollection}" > > labelFunction="entriesLabelFunc"/> > > > > > > >