1 Reply Latest reply on Apr 16, 2007 8:01 PM by jpwrunyan

    Show Row Number in DataGrid Column

    BLXWebMaster Level 1
      I have a data grid and I want the First Column to display a "Record Number". Ie; 1,2,3 etc. The record number is persistant and should stay in order regardless of sorting, filtering etc.

      Any guidence is appreciated.
        • 1. Show Row Number in DataGrid Column
          jpwrunyan Level 1
          This isn't maybe the best way to do it but...

          function getRowNo(rowItem:Object, col:DataGridColumn):String {
           for (var i:int = 0; i<dataGrid_inst.dataProvider.length; i++) {
            if (dataGrid_inst.dataProvider[ i ] == rowItem) {
             return String( i );
            }
           }
          }

          and (sorry, quick and dirty code:)
          <mx:DataGrid>
          <mx:columns>
          <mx:DataGridColumn labelFunction="getRowNo" />
          </>
          </>

          that should get you started down the right road. My recommendation is to actually extend your own DataGrid class or DataGridColumn class in AS and change the above code to use ICollectionView (sp?) instead of dataProvider.
          That way you can internalize the code and not have to write it into every single container component that has an instance of DataGrid.