1 Reply Latest reply on Jun 9, 2008 5:00 PM by ntsiii

    ArrayCollection and DataGrid with ComboBox

    Sunkaras
      Hi,

      In my below code I am filling the ArrayCollection "ordersOnHoldColl" in the function processResult().
      And then I am passing the ArrayCollection to DataGrid as dataProvider.
      In the DataGrid I have a comboBox which I need to fill from a sting in the ArrayCollection.
      from my wer servie request I will get a string like "India,China,Jpaan,Itlay,France" in the field BPDAT.
      if I can fill this string into BPDAT as an array then I can pass that array as dataProvider="{data.BPDAT}" for the ComboBox.
      Please help me how to write the code for it in the function processResult().

      MXML code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%">
      <mx:WebService id="srv1" useProxy="false" wsdl=" http://klang.synopsys.com:9004/sap/bc/srt/rfc/sap/Z_CREDIT_DASH_BOARD_03?sap-client=910&am p;wsdl=1.1"
      showBusyCursor="true">

      <mx:operation name="Z_F_AR_ORDERS_ON_HOLD" resultFormat="e4x" result="processResult()">
      <mx:request>
      <I_PAYER>
      {Application.application.dg.selectedItems}
      </I_PAYER>
      <E_HOLD_ORDERS/>
      </mx:request>
      </mx:operation>

      <mx:operation name="Z_F_AR_CREDIT_RELEASE" resultFormat="e4x">
      <mx:request>
      <I_ORDER>
      {onHold.selectedItems}
      </I_ORDER>
      <E_ORD_MSG/>
      </mx:request>
      </mx:operation>
      </mx:WebService>

      <mx:Script>
      <![CDATA[
      import mx.controls.ComboBox;
      import mx.collections.ArrayCollection;
      import mx.controls.CheckBox;
      import mx.events.CloseEvent;
      import mx.managers.PopUpManager;
      import mx.controls.Alert;
      import mx.core.Application;

      [Bindable]
      private var ordersOnHoldColl:ArrayCollection = new ArrayCollection();

      [Bindable]
      private var collection:Array = new Array()

      public function sendRequest():void{
      srv1.Z_F_AR_ORDERS_ON_HOLD.send();
      ordersOnHoldColl.removeAll()
      }

      public function creditRelease():void{
      if(onHold.selectedItems.length != 0){
      var selIndicesArr:Array = [];
      var dataProvLen:int = ordersOnHoldColl.length;
      for(var i:int = 0; i < dataProvLen; i++){
      if(ordersOnHoldColl .isRowSelected){
      selIndicesArr.push(i);
      }
      }
      if(selIndicesArr.length != 0){
      onHold.selectedIndices = selIndicesArr;
      }

      collection =[];
      var noOfRowsSelected:int = onHold.selectedIndices.length;
      for(var j:int = 0; j < noOfRowsSelected; j++){
      var selIndex:int = onHold.selectedIndices[j];
      collection.push(ordersOnHoldColl[selIndex]);
      }

      srv1.Z_F_AR_CREDIT_RELEASE.send();
      sendRequest();
      }else{

      Alert.show('Please select atleast One Sales Order to Release');
      }

      }

      public function updateSelectedRowFlag(event:MouseEvent):void{
      var currSource:CheckBox = CheckBox(event.currentTarget);
      var selIndex:int;
      if(currSource.selected){
      selIndex = onHold.selectedIndex;
      ordersOnHoldColl[selIndex].isRowSelected = true;
      }
      else{
      selIndex = onHold.selectedIndex;
      ordersOnHoldColl[selIndex].isRowSelected = false;
      }
      }

      public function processResult():void{
      var result:XML = new XML(srv1.Z_F_AR_ORDERS_ON_HOLD.lastResult);
      var list:XMLList = srv1.Z_F_AR_ORDERS_ON_HOLD.lastResult.E_HOLD_ORDERS.item;

      var obj:Object = {isRowSelected: false}
      ordersOnHoldColl.addItem(obj);

      var item:XML;
      for each(item in list){
      var obj_val:Object = {BUKRS:item.child("BUKRS").toString(),
      SBGRP:item.child("SBGRP").toString(),
      KUNNR:item.child("KUNNR").toString(),
      NAME1:item.child("NAME1").toString(),
      VBELN:item.child("VBELN").toString(),
      VDATU:item.child("VDATU").toString(),
      ZTERM:item.child("ZTERM").toString(),
      NETWR:item.child("NETWR").toString(),
      ON_HOLD:item.child("ON_HOLD").toString(),
      SOANM:item.child("SOANM").toString(),
      BPDAT:item.child("BPDAT").toString(),
      EV_EMAIL:item.child("EV_EMAIL").toString()}
      ordersOnHoldColl.addItem(obj_val);
      }
      ordersOnHoldColl.removeItemAt(0);
      }
      public function downordershold():void
      {
      var str: String = new String();
      str = Application.application.con_str ;
      str = 'CDHO' + ',' + ' ' + ',' + Application.application.con_str ;
      // Alert.show(" " + Application.application.con_str);
      ExternalInterface.call( "downloadtoExcel" , str );
      }
      ]]>
      </mx:Script>
      <mx:HBox width="100%">
      <mx:HBox width="100%" height="3%" verticalAlign="middle" >
      <mx:Spacer width="150" />
      <mx:Button label="Download" click="downordershold()"/>
      <mx:Spacer width="750" />
      <mx:Button label="Release" fontSize="12" click="creditRelease()" />
      </mx:HBox>
      </mx:HBox>
      <mx:DataGrid width="98%" height="98%" allowMultipleSelection="true" id="onHold" dataProvider="{ordersOnHoldColl}">
      <mx:columns>
      <mx:DataGridColumn headerText="Release Box" dataField="" width="13" >
      <mx:itemRenderer>
      <mx:Component>
      <mx:CheckBox selected="{data.isRowSelected}" click="outerDocument.updateSelectedRowFlag(event);"/>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      <mx:DataGridColumn headerText="Company Code" dataField="BUKRS" width="20"/>
      <mx:DataGridColumn headerText="Crd Rep(Company Code Wiew" dataField="SBGRP" width="20"/>
      <mx:DataGridColumn headerText="Payer Number" dataField="KUNNR" width="20"/>
      <mx:DataGridColumn headerText="Payer Name" dataField="NAME1" width="30"/>
      <mx:DataGridColumn headerText="Order Number" dataField="VBELN" width="20"/>
      <mx:DataGridColumn headerText="Delievery Date" dataField="VDATU" width="20"/>
      <mx:DataGridColumn headerText="Payment terms" dataField="ZTERM" width="25"/>
      <mx:DataGridColumn headerText="Order Value" dataField="NETWR" width="25"/>
      <mx:DataGridColumn headerText="On hold value" dataField="ON_HOLD" width="25"/>
      <mx:DataGridColumn headerText="SOA name" dataField="SOANM" width="30"/>
      <mx:DataGridColumn headerText="Bill plan" width="25"/>
      <mx:DataGridColumn headerText="Bill Plan" width="150">
      <mx:itemRenderer>
      <mx:Component>
      <mx:ComboBox dataProvider="{data.BPDAT}" />
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      <mx:DataGridColumn headerText="SOA Email" dataField="EV_EMAIL" width="20" visible="false"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:VBox>