1 Reply Latest reply on Nov 19, 2007 6:15 AM by ntsiii

    Complex E4X query dataFields for DataGrid

    JustinFitzsimmons
      Hi all, still fighting with DataGrids. For today, lets assume I have some XML like this:

      var testData : XML =
      <categories>
      <category name="Category 1" id="1">
      <item year="2007">300</item><item year="2008">400</item><item year="2009">500</item>
      </category>
      <category name="Category 2" id="2">
      <item year="2007">600</item><item year="2008">500</item><item year="2009">300</item>
      </category>
      </categories>;

      And later, I define my DataGrid:

      <mx:DataGrid id="test" editable="true" height="100%" width="100%" dataProvider="{testData.category}" textAlign="center" alternatingItemColors="[#FFFFFF,#EAEAEA]" draggableColumns="false" >
      <mx:columns>
      <mx:DataGridColumn headerText="Category" dataField="@name" />
      <mx:DataGridColumn headerText="2007" dataField="item.(@year==2007)" />
      </mx:columns>
      </mx:DataGrid>

      I eventually want to define the columns dynamically, which I can do. But first, I need to figure out how to populate the columns. Why doesn't this E4X item.(@year==2007) query work properly? I can do Alert.show( testData.category.item.(@year==2007) ) in a script portion of the mxml, and it returns the fields that are expected.

      Thanks,

      Justin