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

    Binding Datagrid XML Data

    themoogler
      Hi,
      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".
      quote:

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

      <exist:result exist:hits="1" exist:start="1" exist:count="1" xmlns:exist=" http://exist.sourceforge.net/NS/exist">
      <schedule>
      <tournament>
      <sport>Testing Our DTD</sport>
      <tname>Well-formed Document</tname>
      <match>
      <mdate>Oct. 12, 2007</mdate>
      <competitor>
      <cname>sd</cname>
      <score>2</score>
      </competitor>
      <competitor>
      <cname>sdgs</cname>
      <score>3</score>
      </competitor>
      <location>
      <city>San Luis Obispo</city>
      <state>CA</state>
      <country>USA</country>
      <stadium>Test Stadium, OPTIONAL</stadium>
      </location>
      <tv>SVN</tv>
      <description>Basic testing...</description>
      </match>
      </tournament>
      </schedule>
      </exist:result>
      I receive the data fine however, I cannot nested elements of the XML nodes I retrieve. Here is my data grid.
      quote:

      <mx:DataGrid id="grid" width="446" height="100%" dataProvider="{searchRequest.lastResult.schedule.tournament.match}" enabled="true">
      <mx:columns>
      <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"/>
      </mx:columns>
      </mx:DataGrid>
      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.