1 Reply Latest reply on Mar 17, 2007 6:35 AM by [PiG]

    Using XML attributes in itemRenderer ans labelFunction

    [PiG]
      Hi!

      I've been searching for hours and reading the devguide but still can't find the solution to my problem.
      I have an xml returned from php like this:
      <records>
      <record id="1" name="name_1" type="0"/>
      <record id="2" name="name_2" type="0"/>
      <record id="3" name="name_3" type="1/>
      </records>

      I can bind the result returned through HTTPService to a DataGrid:

      <mx:DataGrid dataProvider="{ret_XML.record}" width="500" rowCount="20" editable="false" id="dg">
      <mx:columns>
      <!-- NEXT LINE IS WORKING!-->
      <mx:DataGridColumn headerText="Name" dataField="@name" width="300"/>
      <!-- LABELFUNC NOT WORKING IN NEXT LINE -->
      <mx:DataGridColumn headerText="Type" dataField="@type" labelFunction="labelFunc">
      </mx:DataGridColumn>
      <mx:DataGridColumn headerText="Id" dataField="@id" editable="false">
      <mx:itemRenderer>
      <mx:Component>
      <!--NEXT LINE IS NOT WORKING! -->
      <mx:Button label="{data.@id}"/>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      </mx:columns>
      </mx:DataGrid>

      and I have a labelFunction like this:

      private function labelFunc(item:Object, column:DataGridColumn):String{
      return "Type: " + item.@type;
      }

      So, my problem is that when I bind the column to an XML attribute it works fine but when I try to bind it to an itemRenderer or use it in a function it is not working. I'm trying it for hours now but just can't get it working.
      I tried:
      <mx:Button label="{data.@id}"/>
      <mx:Button label="{data.(@id)}"/>
      <mx:Button label="{@data.id}"/>

      and maybe others but no luck...
      Please someone help me with this one!

      ty:
      [PiG]
        • 1. Re: Using XML attributes in itemRenderer ans labelFunction
          [PiG] Level 1
          Problem solved!

          Well, after posting to the forum I solved my problem as follows:

          <mx:Button label="{data.attribute('id')}"/>

          So, in itemRenderer just use data.attribute() with the desired XML attribute name


          And in the labelFunction :

          private function labelFunc(item:Object, column:DataGridColumn):String{
          return "Type: " + item.attribute('type');
          }
          Same as with itemRenderer but instead data use item.attribute()


          I hope this is the 'official' solution too...

          [PiG]