1 Reply Latest reply on Sep 13, 2009 2:09 AM by Andrew Rosewarn

    display the rowIndex




      This should be simple, but I would like to display the rowIndex in one of the columns of a datagrid (starting with 1).  The dataprovider is of type ArrayCollection.  The datagrid has drag/drop enabled so the items can be re-arranged, but I would like to keep the rowIndex static (always 1,2,3...etc).  Think arranging songs in a music playlist.  I've stumbled across some blogs recommending using item renderers, but that just seems like overkill to me.  I also saw this (http://forums.adobe.com/message/173512#173512), but don't quite understand how to implement this.  Any help would be greatly appreciated.





        • 1. Re: display the rowIndex
          Andrew Rosewarn

          Hi there


          Yea I don't think you need an item renderer.  You can use a label function like this to obtain the row index, which will work when you drag and reorder.


          <?xml version="1.0"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"   xmlns:ns1="*">




          import mx.collections.ArrayCollection;



          private var ac:ArrayCollection = new ArrayCollection([

          {song: 'Song 1'},

          {song: 'Song 2'},

          {song: 'Song 3'},

          {song: 'Song 4'}



          private function lfRowNum(item:Object,col:int):String


              var index:int = ac.getItemIndex(item) + 1;

              return String(index);





          <mx:DataGrid id="dg" dataProvider="{ac}" dragMoveEnabled="true" dragEnabled="true" dropEnabled="true">


          <mx:DataGridColumn headerText="No" labelFunction="lfRowNum"/>

          <mx:DataGridColumn headerText="Song" dataField="song"/>





          Hope that helps