1 Reply Latest reply on Oct 26, 2007 2:59 AM by Sreenivas R

    Binding Datagrid XML Data

      Summary: I cannot get my DataGrid binding with XML data. Specifically, I cannot bind a DataGridColumn with a child of a child using the dataField property. However, I can bind with a direct child.

      I'm currently building an application where I retrieve data from a XML database and contact it through posting a XQuery to the database. I set the resultFormat of my HTTPServer to "e4x".

      <mx:HTTPService id="searchRequest" url=" http://localhost:8080/exist/rest/db/" contentType="application/xml" useProxy="false"
      method="POST" resultFormat="e4x" />
      I receive this data:

      <exist:result exist:hits="1" exist:start="1" exist:count="1" xmlns:exist=" http://exist.sourceforge.net/NS/exist">
      <sport>Testing Our DTD</sport>
      <tname>Well-formed Document</tname>
      <mdate>Oct. 12, 2007</mdate>
      <city>San Luis Obispo</city>
      <stadium>Test Stadium, OPTIONAL</stadium>
      <description>Basic testing...</description>
      I receive the data fine however, I cannot nested elements of the XML nodes I retrieve. Here is my data grid.

      <mx:DataGrid id="grid" width="446" height="100%" dataProvider="{searchRequest.lastResult.schedule.tournament.match}" enabled="true">
      <mx:DataGridColumn headerText="Tournament" />
      <mx:DataGridColumn headerText="Match Date" dataField="mdate" />
      <mx:DataGridColumn headerText="Sport" />
      <mx:DataGridColumn headerText="City" dataField="location.city"/>
      <mx:DataGridColumn headerText="State" dataField="location.state"/>
      The 'mdate' shows up however, 'location.city' and 'location.state' do not. I am not sure how the dataField works. Does it get the 'current' node and allow me to drill down in the XML node?
      I will note that I can get it working with a labelFunction and an ItemRenderer. I feel that using either of those methods for this is a bit verbose.
        • 1. Re: Binding Datagrid XML Data
          Sreenivas R Adobe Employee
          The default DGColumn picks up the property value by doing data[dataField]. Due to this the nested value would not be picked up.

          By extending DGColumn and overriding the itemToLabel function it is possible to get the desired functionality by adding code to detect "field1.field2" kind of dataField value and returning the nested value.

          This custom DGColumn can be used whererever the functionality is desired.