3 Replies Latest reply on May 18, 2009 9:23 AM by G009

    Please help me getting these datagrid outputs

    G009 Level 1

      Hello guys,

       

      Here m putting two files one mxml code and sample xml file. I modified the xml file so that i can get the output which m getting in this mxml.

      But whatever i did is just a modifications in order to get those outputs. I want efficient way to get those outputs no matter what xml file data is. I tried a lot and finally i cam up with this mxml. But i am not happy with the code. It feels like cheating in order to get those outputs. Please help me friends.

      I have pasted code and xml data over here.

       

       

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

       


      <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;

       


      [Bindable]public var expenses:XMLListCollection;

       

       

       

      public function xmlHandler(evt:ResultEvent):void{

       

      var list:XMLList = evt.result..VALUES;
      expenses = new XMLListCollection(list);
      }

       

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

       

      public function create():void {

       

      data.send();
      }

       

      public function showme():void {
      var value:String;
      for each(var item:XML in expenses){
      value = item.ro.toString();
      }
      Alert.show(value);

       

      }

       

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

       

      switch(num)
      {
      case 1:{   
              adg = new AdvancedDataGrid();
              adg.dataProvider=expenses;
              adg.width = 1000;
              adg.height = 500;
              adg.sortableColumns = false;
                                     
              var adgcolumn12:AdvancedDataGridColumn = new AdvancedDataGridColumn();
              clms = adg.columns;

       

                  adgcolumn12.dataField = "ro";
                  adgcolumn12.headerText = "city";
                 
                          var adgcolumn13:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn13.dataField = "col1";
                          adgcolumn13.headerText = "Private";
                          var adgcolumn14:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn14.dataField = "col2";
                          adgcolumn14.headerText = "Public";
                          var adgcolumn15:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn15.dataField = "col3";
                          adgcolumn15.headerText = "None";
                     
              clms.push(adgcolumn12);
              clms.push(adgcolumn13);
              clms.push(adgcolumn14);
              clms.push(adgcolumn15);
             
              adg.groupedColumns=clms;
              var hbox3:HBox = new HBox();
              hbox3.addChild(adg);

       

              subpan.removeAllChildren();
              subpan.title = "Normal DataGrid using Actionscript";
              subpan.height = 500;
              subpan.width = 1000;
              subpan.addChild(hbox3);
              }
              break;
                 
      case 2:{
              adg = new AdvancedDataGrid();
              adg.dataProvider=expenses;
              adg.width = 1000;
              adg.height = 500;
              adg.sortableColumns = false;
                                     
              var adgcol:AdvancedDataGridColumn = new AdvancedDataGridColumn();
              var adgcolumngroup:AdvancedDataGridColumnGroup = new AdvancedDataGridColumnGroup();
              var adgcolumngroup1:AdvancedDataGridColumnGroup = new AdvancedDataGridColumnGroup();

       

              clms = adg.columns;

       

                  adgcol.dataField = "ro";
                  adgcol.headerText = "city";
                  adgcolumngroup.headerText = "Transport";
                 
                          var adgcolumn3:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn3.dataField = "col1";
                          adgcolumn3.headerText = "Private";
                          adgcolumngroup.children.push(adgcolumn3);
                          var adgcolumn4:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn4.dataField = "col2";
                          adgcolumn4.headerText = "Public";
                          adgcolumngroup.children.push(adgcolumn4);
                          var adgcolumn5:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn5.dataField = "col3";
                          adgcolumn5.headerText = "None";
                          adgcolumngroup.children.push(adgcolumn5);

       

                  adgcolumngroup1.headerText = "Population";
                 
                          var adgcolumn6:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn6.dataField = "col1";
                          adgcolumn6.headerText = "Men";
                          adgcolumngroup1.children.push(adgcolumn6);
                          var adgcolumn7:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn7.dataField = "col2";
                          adgcolumn7.headerText = "Women";
                          adgcolumngroup1.children.push(adgcolumn7);
                          var adgcolumn8:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn8.dataField = "col3";
                          adgcolumn8.headerText = "Children";
                          adgcolumngroup1.children.push(adgcolumn8);

       

                     
              clms.push(adgcol);
              clms.push(adgcolumngroup);
              clms.push(adgcolumngroup1);
             
              adg.groupedColumns=clms;
              var hbox23:HBox = new HBox();
              hbox23.addChild(adg);

       

              subpan.removeAllChildren();
              subpan.title = "Column By DataGrid using Actionscript";
              subpan.height = 500;
              subpan.width = 1000;
              subpan.addChild(hbox23);
              }
              break;       
      case 3:{
             
              adg = new AdvancedDataGrid();
              adg.dataProvider=expenses;
              adg.width = 1000;
              adg.height = 500;
              adg.sortableColumns = false;
                                     
              var adgcolumn1:AdvancedDataGridColumn = new AdvancedDataGridColumn();
              var adgcolumn2:AdvancedDataGridColumn = new AdvancedDataGridColumn();

       

              clms = adg.columns;

       

                  adgcolumn1.dataField = "row";
                  adgcolumn1.headerText = "Country";
                  adgcolumn2.dataField = "ro";
                  adgcolumn2.headerText = "city";
                 
                          var adgcolumn33:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn33.dataField = "col1";
                          adgcolumn33.headerText = "Private";
                          var adgcolumn34:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn34.dataField = "col2";
                          adgcolumn34.headerText = "Public";
                          var adgcolumn35:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn35.dataField = "col3";
                          adgcolumn35.headerText = "None";

       

              clms.push(adgcolumn1);
              clms.push(adgcolumn2);
              clms.push(adgcolumn33);
              clms.push(adgcolumn34);
              clms.push(adgcolumn35);
             
              adg.groupedColumns=clms;
              var hbox33:HBox = new HBox();
              hbox33.addChild(adg);

       

              subpan.removeAllChildren();
              subpan.title = "Group By DataGrid using Actionscript";
              subpan.height = 500;
              subpan.width = 1000;
              subpan.addChild(hbox33);
              }
              break;   
             
      case 4:{
             
              adg = new AdvancedDataGrid();
              adg.dataProvider=expenses;
              adg.width = 1000;
              adg.height = 500;
              adg.sortableColumns = false;
                                     
              var adgcolumn41:AdvancedDataGridColumn = new AdvancedDataGridColumn();
              var adgcolumn42:AdvancedDataGridColumn = new AdvancedDataGridColumn();
              var adgcolumngroup4:AdvancedDataGridColumnGroup = new AdvancedDataGridColumnGroup();
              var adgcolumngroup5:AdvancedDataGridColumnGroup = new AdvancedDataGridColumnGroup();

       

              clms = adg.columns;

       

                  adgcolumn41.dataField = "row";
                  adgcolumn41.headerText = "Country";
                  adgcolumn42.dataField = "ro";
                  adgcolumn42.headerText = "city";
                  adgcolumngroup4.headerText = "Transport";
                 
                          var adgcolumn43:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn43.dataField = "col1";
                          adgcolumn43.headerText = "Private";
                          adgcolumngroup4.children.push(adgcolumn43);
                          var adgcolumn44:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn44.dataField = "col2";
                          adgcolumn44.headerText = "Public";
                          adgcolumngroup4.children.push(adgcolumn44);
                          var adgcolumn45:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn45.dataField = "col3";
                          adgcolumn45.headerText = "None";
                          adgcolumngroup4.children.push(adgcolumn45);

       

                  adgcolumngroup5.headerText = "Population";
                 
                          var adgcolumn46:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn46.dataField = "col1";
                          adgcolumn46.headerText = "Men";
                          adgcolumngroup5.children.push(adgcolumn46);
                          var adgcolumn47:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn47.dataField = "col2";
                          adgcolumn47.headerText = "Women";
                          adgcolumngroup5.children.push(adgcolumn47);
                          var adgcolumn48:AdvancedDataGridColumn = new AdvancedDataGridColumn();
                          adgcolumn48.dataField = "col3";
                          adgcolumn48.headerText = "Children";
                          adgcolumngroup5.children.push(adgcolumn48);

       

                     
              clms.push(adgcolumn41);
              clms.push(adgcolumn42);
              clms.push(adgcolumngroup4);
              clms.push(adgcolumngroup5);
             
              adg.groupedColumns=clms;
              var hbox43:HBox = new HBox();
              hbox43.addChild(adg);

       

              subpan.removeAllChildren();
              subpan.title = "Complex DataGrid using Actionscript";
              subpan.height = 500;
              subpan.width = 1000;
              subpan.addChild(hbox43);
              }
              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="bt2" label="Normal Grid" click="init(1)"/>
      <mx:Button id="bt3" label="Column By DataGrid" click="init(2)"/>
      <mx:Button id="bt4" label="Group By DataGrid" click="init(3)"/>
      <mx:Button id="bt5" label="Complex DataGrid" click="init(4)"/>
      </mx:HBox>

       

      <mx:Panel id="subpan" height="200" width="1000"/>
      </mx:Panel>
      </mx:Application>

       

       

      ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ -----------------------------------

       

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

       

      <VALUES><row>India</row><ro>Mumbai</ro><col1>78</col1><col2>99</col2><col3>90</col3></VALU ES>
      <VALUES><row></row><ro>Delhi</ro><col1>6</col1><col2>56</col2><col3>77</col3></VALUES>
      <VALUES><row></row><ro>Banglore</ro><col1>5</col1><col2>0</col2><col3>11</col3></VALUES>
      <VALUES><row>USA</row><ro>New York</ro><col1>8</col1><col2>9</col2><col3>0</col3></VALUES>
      <VALUES><row></row><ro>Boston</ro><col1>60</col1><col2>50</col2><col3>70</col3></VALUES>
      <VALUES><row></row><ro>Atlanta</ro><col1>51</col1><col2>01</col2><col3>99</col3></VALUES>
      </XMLDocument>