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

    display the rowIndex

    joeroth2010

      Hi,

       

      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.

       

      Thanks,

       

      Joe

        • 1. Re: display the rowIndex
          Andrew Rosewarn Level 3

          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="*">

           

          <mx:Script>

          <![CDATA[

          import mx.collections.ArrayCollection;

           

          [Bindable]

          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:Script>

           

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

          <mx:columns>

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

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

          </mx:columns>

          </mx:DataGrid>

          </mx:Application>

           

          Hope that helps

           

          Andrew