tags:

views:

510

answers:

3

I have an array like the following one

public var sal:Array=[
     {empNo:1001, sal:1000, exp:400},
     {empNo:1002,    sal:3000, exp:240},
     {empNo:1003,    sal:1000, exp:452},
     {empNo:1004,    sal:5000, exp:348},
     ......
     {empNo:1550,    sal:2000, exp:330},

     ];

I need to show data using a 3 row flex data grid where the first row will display empNo, the second row will display corresponding salary(field sal), and the third row will display Expenditure (field exp).

Can you tell me how to do this?

A: 

Actually I meant to say that data will come into a dataGrid in a format as given below Row 1:->Emp No 1001 1002 1003 Row 2:->Sal 1000 3000 1000 Row 3:->exp 400 240 452

A: 

Here is your solution

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="formatData()">
    <mx:Script>
     <![CDATA[
      import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
      import mx.collections.ArrayCollection;
      [Bindable]
      var dp:ArrayCollection=new ArrayCollection();

      private function formatData():void
      {
       var salArray:Array=[{empNo: 1001, sal: 1000, exp: 400}, {empNo: 1002, sal: 3000, exp: 240}, {empNo: 1003, sal: 1000, exp: 452}, {empNo: 1004, sal: 5000, exp: 348}];
       var i:int=0;
       var empNo:Object=new Object();
       var sal:Object=new Object();
       var exp:Object=new Object();
       var columns:Array = new Array();

       for (i=0; i < salArray.length; i++)
       {
        empNo["col"+i]=salArray[i].empNo;
        sal["col"+i]=salArray[i].sal;
        exp["col"+i]=salArray[i].exp;
        var advancedDataGridColumn:AdvancedDataGridColumn=new AdvancedDataGridColumn();  
        advancedDataGridColumn.dataField="col"+i;
        columns.push(advancedDataGridColumn);
       }

       dp.addItem(empNo);
       dp.addItem(sal);
       dp.addItem(exp);
       adg1.columns=columns;
       adg1.invalidateDisplayList();
      }
     ]]>
    </mx:Script>
    <mx:AdvancedDataGrid x="40.5" y="163" id="adg1" designViewDataType="flat" dataProvider="{dp}">  
    </mx:AdvancedDataGrid>

</mx:Application>

i think this is what you asked :)

Rahul Garg
A: 

Yes.Thanks a lot rahul