1 Reply Latest reply on Jul 30, 2010 4:17 AM by jfb00

    Add Columns dynamically issue

    Benoitcn Level 1

      I can't pass the data to the new created columns in the datagrid.

      Even if I refresh the dataprivoider properties.

      I can't judge the problem is the data can't pass to the columns

      or the columns don't point to the current data which I use red color lined.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
          layout="absolute"
          minWidth="955"
          minHeight="600">
      <mx:Script>
        <![CDATA[
         import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
         import mx.controls.advancedDataGridClasses.AdvancedDataGridColumnGroup;

         [Bindable]
         public static var xmlData:XML=<data>
           <row Actual1="44985" Estimate1="45000" Actual2="44985" Estimate2="45000" Actual3="44985" Estimate3="45000"/>
          </data>;

         protected function button1_clickHandler(event:MouseEvent):void
         {

          var adgcg:AdvancedDataGridColumnGroup=new AdvancedDataGridColumnGroup("Employee");
          var adgc:AdvancedDataGridColumn;
          var arr:Array=new Array();

          for each (var j:*in emp[0].*)
          {

           trace("node name of each child \n" + j.name());

           adgc=new AdvancedDataGridColumn(j.name());
           adgc.dataField=j.name();
           //adgcg.children.push(adgc);     doesn't work
           arr.push(adgc); // doesn't work too ~
          }

          adgcg.children=arr;
          dg.groupedColumns=[adgcg];
          dg.dataProvider.refresh();
         }
        ]]>
      </mx:Script>

       

      <mx:XMLList id="emp">
        <employee>
         <name>Christina Coenraets</name>
         <phone>555-219-2270</phone>
         <email>ccoenraets@fictitious.com</email>
         <active>true</active>
         <image>images/arrow_icon_sm.png</image>
        </employee>
        <employee>
         <name>Joanne Wall</name>
         <phone>555-219-2012</phone>
         <email>jwall@fictitious.com</email>
         <active>true</active>
        </employee>
        <employee>
         <name>Maurice Smith</name>
         <phone>555-219-2012</phone>
         <email>maurice@fictitious.com</email>
         <active>false</active>
        </employee>
        <employee>
         <name>Mary Jones</name>
         <phone>555-219-2000</phone>
         <email>mjones@fictitious.com</email>
         <active>true</active>
        </employee>
        <employee>
         <name>Benoit Hoyee</name>
         <phone>525-220-2228</phone>
         <email>sdkennes@fictitious.com</email>
         <active>false</active>
        </employee>
        <employee>
         <name>Jack Jones</name>
         <phone>125-219-2000</phone>
         <email>Mcones@fictitious.com</email>
         <active>true</active>
        </employee>
        <employee>
         <name>Luonce Jos</name>
         <phone>555-219-872</phone>
         <email>Jos@cncn.com</email>
         <active>true</active>
        </employee>
      </mx:XMLList>

       

      <mx:VBox autoLayout="true"
          width="1200"
          height="700">
        <mx:AdvancedDataGrid id="dg"
              dataProvider="{emp}"
              width="800"
              height="400">
         <mx:groupedColumns>
          <mx:AdvancedDataGridColumnGroup headerText="Employee">
           <mx:AdvancedDataGridColumn headerText="Name"
                    dataField="name"/>
          </mx:AdvancedDataGridColumnGroup>
         </mx:groupedColumns>
        </mx:AdvancedDataGrid>
        <mx:Button click="button1_clickHandler(event)"
             label="CreateGroup"/>
      </mx:VBox>

       

      </mx:Application>