1 Reply Latest reply on Nov 10, 2009 10:20 AM by Subeesh Arakkan

    Using labelfunction as numbering

    Pii T

      I have been trying to create a "No." column in my datagrid and wasn't sure, how I can achieve that.


      I just want one column to display 1, 2, 3, 4,...... and so on equivalent to the numbers of objects I bind to the datagrid.


      I would be highly appreciated if you guys could point me to easy links or give me some examples.


      Thank you.

        • 1. Re: Using labelfunction as numbering
          Subeesh Arakkan Level 4



          Try this code


                      public var dp:ArrayCollection = new ArrayCollection(
                          [ {label:"Visa", data:1},
                            {label:"MasterCard", data:2},
                            {label:"American Express", data:3} ]);
                      private function numberFunction(data:Object,column:DataGridColumn):String
                          return "No: " + ( dp.getItemIndex(data) + 1).toString();




              <mx:DataGrid id="myDG" dataProvider="{dp}" width="350">
                     <mx:DataGridColumn headerText="Number" labelFunction="numberFunction" />
                   <mx:DataGridColumn headerText="Label" dataField="label" />