2 Replies Latest reply on Apr 9, 2008 7:41 AM by trainsimple

    Datagrid column question

    trainsimple
      I have a problem with my datagrid columns populating with content.

      Here's the xml structure:

      Code:
      <headline>Bridgeport whipper-snap</headline>
      <blurb>Some text</blurb>
      location_url>whipsnap.swf</location_url>
      <location_url_videotype>1</location_url_videotype>
      <podcast_url_videotype>2</podcast_url_videotype>
      <owner id="325" name="Bridgeport" />

      And here's what I'm doing:

      MXML Code:

      <mx:DataGrid id="movies" dataProvider="{filterPlay}" width="650" x="50" y="100" editable="true" change="previewMovie()">
      <mx:columns>
      <mx:DataGridColumn dataField="headline" headerText="Movie" editable="false"/>
      <mx:DataGridColumn dataField="owner.@name" headerText="Company" editable="false"/>
      </mx:columns>
      </mx:DataGrid>

      The owner.@name won't populate the column ... nor will owner@name, or @name. How can I get the name attribute of the owner tag to populate a coulmn?

      Thanks!
        • 1. Re: Datagrid column question
          ntsiii Level 3
          Since dataField only takes a string and not an expression, to use it, the data must be in top-level properties of the item object. For xml, this means either first generation child nodes, or attributes of the item node itself.

          Since you have a nested structure (data is in attributes of child nodes), you need to use labelFunction(). A labelFunction automatically gets an "item" argument, which wll contain the item xml, and a DatGridColumn argument, which you can use to make a single labelFunction work with multiple columns.

          You write logic in the labelFunction that traverses the item however you want, and returns a string, which appears in the cell.

          Check the docs, and I have an example on www.cflex.net, search labelFunction.

          Tracy