How do you find an item's dataProvider index from inside an itemRenderer?
The List based classes of Flex all allow you to implement your own custom itemRenderer.
I was working on one of the DotComIt Flex Components. The component is a DataSorter component and allows for easy sorting of data in a manner similar to a Netflix movie queue or YouTube playlists. This component includes buttons for "move to top," "move to bottom," "move up", and move down.
For the first item in the dataProvider, there is no 'up' to move the item to. For the last item in the dataProvider, there is no down to move the items too. If we are displaying the first, or last item in the dataProvider wanted to make the relevant buttons invisible. To do that I needed to know the index location of my data in the dataProvider.
First I looked at the rowIndex in the listData. Unfortunately that display the index of the renderer being displayed, not the index of the item in the dataProvider. I settled on this approach:
ListCollectionView(this.listOwner.dataProvider).getItemIndex(this.data)
It appears to be working great for me. Is there an easier way?





itemRendererToIndex(itemRenderer:IListItemRenderer):int
Derek
I had no idea that was there. I guess you learn something new every day. I'm not sure that the getItemIndex does under the hood, but itemRendererToIndex uses the itemRenderer.name and looks for it in a rowMap.
In my travels I haven't needed to 'touch' the rowMap yet. I wonder how itemRenderers are named.
Cool; thanks for the tip!
If you implement IDropInListItemRenderer, then listData.rowIndex + owner.verticalScrollPosition should be your position
Source: http://tech.groups.yahoo.com/group/flexcoders/mess...
I have a customitemrenderer but it is defined in a seperate mxml file. I have a horizontal list that uses the custom itemrenderer. I want to display the a button for each item in the horizontal list as a number so item 1 would have the button label 1, item 2 would have the button label 2 and so on.
can anybody help me? I'm pretty new to this.
The line of code would need to be in your renderer class.
I would listen to the dataChange event and change the button's label in the dataChangeHandler/