2 Replies Latest reply on Aug 24, 2006 9:20 AM by ntsiii

    DataGrid dataprovider from XML

      When I set the dataprovider for a DataGrid to an ArrayCollection, the grid finds out the column headers from the first row of data as it is supposed to. However, if I set the dataprovider to XML, the datagrid seems unable to find the column headers, and nothing is displayed. If columns are defined in the DataGrid, the XML data is displayed just fine.

      I have pasted in a short app that demonstrates this. In the code below, if you uncomment the DataGrid columns, the data appears.

      This looks suspiciously like a bug to me for a couple of reasons.

      Firstly I traced into the Flex code and could see the code spot the fact that the data was XML. Then DataGrid::collectionChangeHandler tries to generate the columns, but it returns an empty array. So the it appears that the code is there and it intends to generate the columns from XML data, but it doesn't work :-)

      Secondly, everywhere I see a reference to setting the dataprovider for a DataGrid, is seems to indicate that this should work. In other words, I haven't seen anything that explicitly states that this doesn't work.

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" initialize="initArrayData()">
      import mx.collections.*;

      private var DGArray:Array = [
      {id:1, code:'STORE1', name:'A Store'},
      {id:2, code:'STORE2', name:'Another Store'},

      public var initDG:ArrayCollection;

      public function initArrayData():void {
      initDG=new ArrayCollection(DGArray);

      private var stores:XML =
      <name>A Store</name>


      <mx:DataGrid id="xmlGrid" width="350" height="200" dataProvider="{stores.store}" >
      <!-- <mx:columns>
      <mx:DataGridColumn dataField="code" />
      <mx:DataGridColumn dataField="name" />
      </mx:columns> -->

      <mx:DataGrid id="arrayGrid" width="350" height="200" dataProvider="{initDG}"/>