1 Reply Latest reply on Nov 16, 2009 12:03 PM by Flex harUI

    single row arrayCollection for datagrid

    cwbowman

      I am having difficulty creating an arrayCollection from a one row xml file.

       

      The error is Error #1034: Type Coercion failed: cannot convert XMLList@60f8699 to Array.

       

      I can make it work by adding an additional 'oadata' row to the xml file.

       

       

      The app displays a multi row datagrid on top of a single row datagrid.

       

      my xml file is:

       

      <?xml version="1.0"?>

      <oadata>

           <data>

                <lastyear>64408706</lastyear>

                <lastmonth>67283222</lastmonth>

                <yesterday>143366536</yesterday>

                <current>139092494</current>

           </data>

      </oadata>

       

       

      Here is the whole app.

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

      initialize="oaDataService.send(),indvDataService.send()">

      <mx:Script>

      <![CDATA[

           import mx.rpc.events.FaultEvent;

           import mx.rpc.events.ResultEvent;

           import mx.collections.ArrayCollection;

           [Bindable]

           private var indvData:ArrayCollection;

           [Bindable]

           private var oaData:ArrayCollection;

       

           private function resultHandler(event:ResultEvent):void{

       

                indvData=event.result.indvdata.row;

           }

           private function resultHandler2(event:ResultEvent):void{

       

                oaData=new ArrayCollection(event.result.oadata.data);

           }

           private function faultHandler(event:FaultEvent):void {

       

           }

           private function currencyLabel(item:Object, column:DataGridColumn):String {

                return currencyFormatter.format(item[column.dataField]);

            }

       

      ]]>

      </mx:Script>

       

      <mx:HTTPService id="indvDataService"

                url="data/testdata.xml" result="resultHandler(event)" fault="faultHandler(event)"/>

      <mx:HTTPService id="oaDataService" url="data/oadata.xml" result="resultHandler2(event)" fault="faultHandler(event)" resultFormat="e4x"/>

       

      <mx:CurrencyFormatter id="currencyFormatter" precision="0" />

      <mx:Style>

              .centered {

                  fontWeight: bold;

                  textAlign: center;

              }

          </mx:Style>

       

      <mx:VDividedBox  width="100%">

       

       

      <mx:DataGrid x="1" y="1" id="IndvState" dataProvider="{indvData}" width="100%"

                height="600" editable="false" fontSize="24"

                headerStyleName="centered">

           <mx:columns>

                <mx:DataGridColumn dataField="nickname"

                     headerText="Nickame" textAlign="right"/>

                <mx:DataGridColumn dataField="calls"

                     headerText="Dispos" textAlign="right" />

                <mx:DataGridColumn dataField="pplan"

                     headerText="Pmt Plans" textAlign="right" />

                <mx:DataGridColumn dataField="promise"

                     headerText="Promises" textAlign="right" />

                <mx:DataGridColumn dataField="tot_seads"

                     headerText="Tot Seads" textAlign="right" />

                <mx:DataGridColumn dataField="tot_balance"

                     headerText="Tot Bal" textAlign="right" labelFunction="currencyLabel" />

                <mx:DataGridColumn dataField="ob_seads"

                     headerText="OB Seads" textAlign="right" />

                <mx:DataGridColumn dataField="ob_balance"

                     headerText="OB Bal"  textAlign="right"  labelFunction="currencyLabel"/>

       

           </mx:columns>

       

      </mx:DataGrid>

      <mx:DataGrid x="1" y="1" id="OAState" dataProvider="{oaData}" width="100%"

                height="75" editable="false" fontSize="24"

                headerStyleName="centered">

           <mx:columns>

                <mx:DataGridColumn dataField= "lastyear"

                     headerText="Last Year"  textAlign="right" labelFunction="currencyLabel" />

                <mx:DataGridColumn dataField="lastmonth"

                     headerText="Last Month"  textAlign="right" labelFunction="currencyLabel" />

                <mx:DataGridColumn dataField="yesterday"

                     headerText="Yesterday"  textAlign="right" labelFunction="currencyLabel" />

                <mx:DataGridColumn dataField="current"

                     headerText="Current"  textAlign="right" labelFunction="currencyLabel" />

      </mx:columns>

      </mx:DataGrid>

       

       

      </mx:VDividedBox>

       

      </mx:Application>