3 Replies Latest reply on Apr 19, 2010 6:53 AM by Sebastien V.

    datagrid lableFunction

    JockMahon

      Is there any way of knowing what row a labelFunction

      function is currently working on, so

       

       

      <mx:DataGridColumn headerText="Total"  dataField="TOTAL_PRICE" labelFunction="calculateTotalPrice" editable="false" minWidth="50"/>

      ..

      ..

      ..

      ..

                  protected function calculateTotalPrice(item:Object, column:DataGridColumn):String
                  {

                          // in here i need to know the row


                  }

        • 1. Re: datagrid lableFunction
          Sebastien V. Level 3

          You can retrieve the DataGrid's dataProvider :

           

          var provider:Object = column.owner.dataProvider;
          

           

          And then look into it to find the item index (ArrayCollection provides the getItemIndex method, but this is only if your DataGrid's dataProvider is an ArrayCollection).

          1 person found this helpful
          • 2. Re: datagrid lableFunction
            JockMahon Level 1

            This is what i get for this

             

            Attempted access of inaccessible property owner through a reference with static type mx.controls.dataGridClasses:DataGridColumn.
            • 3. Re: datagrid lableFunction
              Sebastien V. Level 3

              Oups, sorry about that. I thought the owner property was public, but its scope is actually mx_internal.

               

              For me there's two solutions :

               

              1- The best would be to use an itemRenderer instead of a labelFunction. If your itemRenderer extends an UIComponent you will be able to access its owner property, which will be the DataGrid.

               

              2- Kind of dirty, but you could extend the DataGridColumn class and implement a public getter on the DataGrid's dataprovider :

               

              import mx.core.mx_internal;
              use namespace mx_internal;
              
              public function get gridProvider():Object {
                   return owner.dataProvider;
              }
              

               

              And access it in your labelFunction.

              The choice is yours...

              1 person found this helpful