4 Replies Latest reply on Dec 8, 2009 4:41 PM by Flex harUI

    How to assign constant line numbers for a DataGrid?


      I assign the DataGrid's rowCount property to 8, which should limit the row number of the DataGrid.


      now I want  the first column of DataGrid to show the line number, which is from 1 to 8.


      this column is just for labelling the line number as a function we can


      find in any TextEditor, it is nothing about the dataProvider of the DataGrid.


      well, How can I add this column?


      any solutions? many thanks!

        • 2. Re: How to assign constant line numbers for a DataGrid?
          niangao Level 1

          Thank you for your reply, I have seen the similar code you post to me, while this is not quite right as I want.


          I want this column to just show the line number such as 1 to 8, it doen't matter how many


          rows of data I get from the dataProvider.


          The DataGrid I want is something like this:


          LineNumber         Name         age

                 1                   adobe         100

                 2                    xx               x







          I just want this LineNumber column show up there always. this column may not get from the dataProvider.


          Can I add such column in a datagrid?


          Hopefully I state my question clearly, thank you for any help.

          • 3. Re: How to assign constant line numbers for a DataGrid?
            RK... Level 3

            You can have something like this


            public class CustomGrid extends HBox {
                 private var rowGrid: DataGrid = new DataGrid();
                 private var grid: DataGrid = new DataGrid();
                 private var rowDataProvider: ArrayCollection = new ArrayCollection();
                 public function CustomGrid() {
                 override protected function createChildren(): void {
                      this.setStyle("horizontalGap", "-1");
                      rowGrid.percentWidth = 10;
                      grid.percentWidth = 90;
                 public function set dataProvider(value: Object): void {
                      this.grid.dataProvider = value;
                 public function get dataProvider(): Object {
                      return this.grid.dataProvider;
                 public function set rowCount(value: int): void {
                      grid.rowCount = value;
                      rowGrid.rowCount = value;
                      for (var i: int = 1; i <= value; i++) {
                           rowDataProvider.addItem({Row: i});
                      rowGrid.dataProvider = rowDataProvider;



            <custom:CustomGrid id="dgSource" dataProvider="{_acDP}" rowCount="8" >
            [Bindable]private var _acDP:ArrayCollection
            public function init():void {
               var oItem:Object;
               _acDP = new ArrayCollection();
               oItem = {Album:"The Lost Chord", Artist:"The Moody Blues", Price:"15.99" };
               oItem = {Album:"Meddle", Artist:"Pink Floyd", Price:"17.99" };
               oItem = {Album:"Trespass", Artist:"Genesis", Price:"18.99" };
               oItem = {Album:"Trespass", Artist:"Genesis", Price:"18.99" };

            • 4. Re: How to assign constant line numbers for a DataGrid?
              Flex harUI Adobe Employee

              You can try using a labelFunction that calls getItemIndex, but that will be too slow if you have a lot of rows


              If you have lots of rows, a custom renderer might work, maybe something like:






                             override public function validateNow():void


                                  if (data && parent)


                                       text = listData.owner.verticalScrollPosition + listData.rowIndex;









              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui