tags:

views:

66

answers:

2

Is there a way to get a s:List to display it's items in reverse order? Not having to make a copy of the dataProvider would be ideal. Thanks.

A: 

The s:List control does not have the option to show items in reverse order. All is controlled by manipulating the dataProvider or the "source" of the dataProvide.

Here is how you could achieve this

public function showReverseList(data:Array):void
{
    var reverseList:Array;
    var i,count = data.length;

    for(i = count-1 ; i >= 0 ; i--)
    {
        // add items in reverse order
        reverseList.push(data[i]);
    }

    myListControl.dataProvider = reverseList;
}
Adrian Pirvulescu
Thanks for the suggestion, this is what's already in place. I'm just wondering if there's a better way to do it. I find it hard to believe that there's nothing built-in to achieve that.
sharvey
trust me... there is nothing like that inside the list. and if there would be one, it would like like the code you already have.
Adrian Pirvulescu
The layout of the dataGroup inside the list could logically handle it.
sharvey
Sorting the collection as Wade Mueller suggests is the most flexible way of achieving this, especially if you need to change the sort order later. Otherwise you can also use the `Array.reverse()` function to reverse the array in-place.
Sly_cardinal
+1  A: 

You can set a Sort on your dataProvider (assuming it implements ICollectionView, like an ArrayCollection for example) and call the Sort.reverse() method. Hope that helps.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/Sort.html

Wade Mueller