Drag and Drop on a Sorted List Collection in Spark (Flex 4)

So if you sort a list based on a field, and then want to give users the ability to reorder that list, you have a quandary- it seems they are mutually exclusive requirements in a ListCollectionView.

Anyway the only way I’ve found to solve this problem is somewhat inelegant but it works, basically you apply the sort to your collection and then create a new unsorted collection, and copy the items from the original to this new one in the right order.

An example:

var slidesCopy:ArrayCollection = deck.slides as ArrayCollection;
deck.slides = null; 
sortSlidesInDecks(slidesCopy); //Apply the sort
var temp:ArrayCollection = new ArrayCollection();
for each (var slide:SlideVO in slidesCopy)
deck.slides = temp;

If you know of a better way, let me know in the comments!

Leave a Reply

Your email address will not be published. Required fields are marked *

This blog is kept spam free by WP-SpamFree.

Get Adobe Flash player