2 Replies Latest reply on Feb 20, 2009 2:35 PM by G009

    Help needed with AdvancedDataGridColumnGroup

    G009
      Hi Guys,

      I have written this code. I dont know where i'm making mistake, but i am not able to get output.
      My code is as follows:

      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      creationComplete="create()">

      <mx:HTTPService id="head" url="header.do"
      showBusyCursor="true" result="xmlheaderHandler(event)" resultFormat="e4x"/>
      <mx:HTTPService id="data" url="test.do"
      showBusyCursor="true" result="xmlHandler(event)" resultFormat="e4x"/>
      <mx:Script>
      <![CDATA[
      import mx.controls.advancedDataGridClasses.AdvancedDataGridColumnGroup;
      import mx.collections.HierarchicalData;
      import mx.controls.AdvancedDataGrid;
      import mx.utils.ColorUtil;
      import mx.graphics.SolidColor;
      import mx.containers.VBox;
      import mx.containers.HBox;
      import mx.collections.XMLListCollection;
      import mx.charts.ColumnChart;
      import mx.charts.series.ColumnSeries;
      import mx.charts.CategoryAxis;
      import mx.charts.Legend;
      import mx.rpc.events.ResultEvent;
      import mx.controls.Alert;
      import mx.controls.dataGridClasses.DataGridColumn;
      import mx.controls.DataGrid;
      import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;

      public var tag1:Number;
      public var tag2:Number;
      [Bindable]public var expenses:XMLListCollection;
      [Bindable]public var header:XMLListCollection;

      public function xmlheaderHandler(evt:ResultEvent):void{
      // Sets testInfo's root as the student. Everything else
      // referenced in respect to this.
      var list:XMLList = evt.result..HEADER;
      header = new XMLListCollection(list);

      }

      public function xmlHandler(evt:ResultEvent):void{
      // Sets testInfo's root as the student. Everything else
      // referenced in respect to this.
      var list:XMLList = evt.result..VALUES;
      expenses = new XMLListCollection(list);

      }

      //Chart variables
      public var myChart1:ColumnChart;
      public var myChart2:ColumnChart;
      public var series1:ColumnSeries;
      public var series2:ColumnSeries;
      public var legend1:Legend;
      public var legend2:Legend;

      //Grid variables
      public var dg:DataGrid = new DataGrid();
      public var adg:AdvancedDataGrid = new AdvancedDataGrid();

      public function create():void {
      head.send();
      data.send();
      }


      public function showme():void {
      var value:String;
      for each(var item:XML in header){
      value = item.COUNT[0].toString();
      }
      Alert.show(value);

      }



      public function init(num:Number):void {
      var i:int;
      var max:int;
      var clms:Array;
      var clms2:Array;
      var xaxis:String;
      var yaxis1:String;
      var yaxis2:String;

      switch(num)
      {
      case 1:{
      for each(var item7:XML in header){
      max = Number(item7..COUNT[0]);
      }
      adg = new AdvancedDataGrid();

      adg.dataProvider=expenses;
      adg.width = 500;
      adg.height = 500;

      clms = adg.columns;

      for each(var item8:XML in header){
      var adgc:AdvancedDataGridColumn = new AdvancedDataGridColumn();
      adgc.dataField = item8..ID[0].toString();
      adgc.headerText = item8..VALUE[0].toString();


      var adgc2:AdvancedDataGridColumn = new AdvancedDataGridColumn();
      var adgcg:AdvancedDataGridColumnGroup = new AdvancedDataGridColumnGroup();
      adgcg.headerText = "Column";
      for(i=1;i<max;i++){
      adgc2.dataField = item8..ID .toString();
      adgc2.headerText = item8..VALUE
      .toString();
      adgcg.children.push(adgc2);
      }
      clms.push(adgc);
      clms.push(adgcg);
      }
      adg.columns=clms;
      var hbox3:HBox = new HBox();
      hbox3.addChild(adg);


      subpan.removeAllChildren();
      subpan.title = "Advanced DataGrid Group using Actionscript";
      subpan.height = 500;
      subpan.width = 500;
      subpan.addChild(hbox3);
      }
      break;
      default:
      Alert.show("Wrong Choice!!");
      break;
      }

      }
      ]]>
      </mx:Script>


      <mx:Panel id="pan">
      <mx:HBox>
      <mx:Button id="bt1" label="Alert" click="showme()"/>
      <mx:Button id="bt4" label="Advanced DataGrid" click="init(1)"/>
      </mx:HBox>

      <mx:Panel id="subpan" height="200" width="200"/>
      </mx:Panel>
      </mx:Application>
      .......................................................................................... .........................................................
      header.xml

      <?xml version="1.0" encoding="utf-8"?>
      <XMLDocument>
      <HEADER>
      <COUNT>3</COUNT>
      <COLUMN><ID>c10</ID><VALUE>Bill Month</VALUE></COLUMN>
      <COLUMN><ID>c11</ID><VALUE>Merchant Amount Average</VALUE></COLUMN>
      <COLUMN><ID>c12</ID><VALUE>Account Count</VALUE></COLUMN>
      </HEADER>
      </XMLDocument>
      .......................................................................................... ........................................................................
      test.xml

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

      <VALUES><c10>Nov 2005</c10><c11>205.2052</c11><c12>463290.84</c12></VALUES>
      <VALUES><c10>Dec 2005</c10><c11>241.817</c11><c12>465985.98</c12></VALUES>
      <VALUES><c10>Jan 2006</c10><c11>231.0464</c11><c12>468981.96</c12></VALUES>
      <VALUES><c10>Feb 2006</c10><c11>191.6681</c11><c12>471546</c12></VALUES>
      <VALUES><c10>Mar 2006</c10><c11>176.813</c11><c12>474083.82</c12></VALUES>
      </XMLDocument>