How do you modify the dataProvider from within an ItemRenderer?

A reader of this blog, Kyle sent in this question to me:

I stumbled across your post ( http://www.jeffryhouser.com/index.cfm/2008/11/4/How-do-you-find-an-items-dataProvider-index-from-inside-an-itemRenderer ) that mentioned you were creating a component that would allow you to move an item up or down within the list from within the itemRenderer. I was wondering if you might be willing to provide me with some insight on how you accomplished this? Any ideas would be greatly appreciated.

I had spent about 3 months or so working on a DataSorter component that lets your users easily sort data in a manner similar to YouTube Playlists or the Blockbuster Online movie queue. I wasn't sure how much detail I wanted to give out to Kyle. But, after some thinking and some e-mails back and forth, I decided there is nothing too revolutionary about the concepts behind this. I expect people to buy my components because it saves them time and money when compared to building it themselves; not because I'm accomplishing the impossible.

This is how I'd approach something like this:

  • Have your itemRenderer broadcast an event. In my situation, I did this based on a button click. Depending upon where you want to respond to the event, you may want the event to bubble.
  • Add a listener function for that event.
  • Modify the dataProvider in the listener function

Kyle was hoping I had some brilliant insight to automatically change the dataProvider upon that button click. I didn't. This is a general algorithm for swapping two items in a dataProvider:

  1. Save Item in Position 1 ( tempItem = AC.getItemAt(position1); )
  2. Set Item at Position 2 to Position 1's spot ( AC.setItemAt(getItemAt(Position2),position1); )
  3. Set saved Item to Position 2 spot ( AC.setItemAt(tempItem,Position2) )

To me, this seems like a pretty standard

This component will be part of the Flextras product line and should be launching soon.

I do like to answer reader questions. So, always feel free to contact me with them. I try to respond in a timely manner (although it doesn't always happen).

Comments
All Content Copyright 2005, 2006, 2007 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.8.