0 Replies Latest reply on Dec 5, 2006 10:51 AM by GeorgeWS

    Datagrid changing dataprovider and back

    GeorgeWS Level 1
      I have a ComboBox and a DataGrid. The grid gets initially filled from an Array called myDollars that comes from the RO qDollars that has an argument (employee). this works fine.
      I make a selection from the ComboBox and the datagrid changes to use the qDollars2 RO and sends the employee and gets the right data back filling the datagrid. this works fine.
      The part I cannot get is when I put the combobox selection back to "Select Rep", the datagrid goes blank. I want it to fill the grid back up with my default when the app is first loaded. how can I do this?

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute"
      creationComplete="initVars()" >

      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.controls.Alert;
      import mx.collections.ArrayCollection;
      import mx.core.Application;
      import mx.utils.ObjectUtil;
      import mx.events.ItemClickEvent;

      [Bindable]
      public var myRep:ArrayCollection;

      [Bindable]
      public var myDollar:ArrayCollection;

      [Bindable]
      public var myDollar2:ArrayCollection;

      [Bindable]
      public var Employee:String;

      [Bindable]
      public var dp:ArrayCollection = myDollar;

      [Bindable]
      public var aReturnTypes: Array = [ {label:"query", data:"query"} ];

      [Bindable]
      public var returnType:String="string";

      public function handleQueryResult1(event:ResultEvent):void{
      myDollar=event.result as ArrayCollection;
      }

      public function handleQueryResult4(event:ResultEvent):void{
      myRep=event.result as ArrayCollection;
      }

      public function handleQueryResult6(event:ResultEvent):void{
      myDollar2=event.result as ArrayCollection;
      }

      [Bindable]
      public var selectedItem:Object;

      public function initVars() : void {
      Employee = Application.application.parameters.Employee;
      SupComp = Application.application.parameters.SupComp;
      qDollars.Dollars(Employee, SupComp);
      Reps.Reps.send();
      qDollars2.Dollars2(Employee, SupComp);
      }

      [Bindable]
      private var newReps:ArrayCollection=new ArrayCollection;

      public function doPrompt2( event:ResultEvent ):void {
      newReps = Reps.Reps.lastResult;
      var prompt:Object = new Object();

      prompt.data = null;
      prompt.label = "Select Rep";

      newReps.addItemAt( prompt, 0 );
      repfilter.selectedIndex = 0;

      if (dp==myDollar) {
      dp = myDollar2;
      } else {
      dp = myDollar;
      }
      }
      ]]>
      </mx:Script>

      <mx:RemoteObject
      id="qDollars"
      destination="ColdFusion"
      source="youngsmarket.programs.sales.salesdm.bin.salesdm"
      showBusyCursor="true" >
      <mx:method name="Dollars" result="handleQueryResult1(event)" fault="Alert.show(event.fault.message)">
      <mx:arguments>
      <employee>{Employee}</employee>
      <supcomp>{SupComp}</supcomp>
      </mx:arguments>
      </mx:method>
      </mx:RemoteObject>

      <mx:RemoteObject
      id="qDollars2"
      destination="ColdFusion"
      source="youngsmarket.programs.sales.salesdm.bin.salesdm"
      showBusyCursor="true" >
      <mx:method name="Dollars2" result="handleQueryResult6(event)" fault="Alert.show(event.fault.message)">
      </mx:method>
      </mx:RemoteObject>

      <mx:RemoteObject
      id="Reps"
      destination="ColdFusion"
      source="youngsmarket.programs.sales.salesdm.bin.salesdm"
      showBusyCursor="true" >
      <mx:method name="Reps" result="doPrompt2( event )" fault="Alert.show(event.fault.message)">
      <mx:arguments>
      <employee>{Employee}</employee>
      <supcomp>{SupComp}</supcomp>
      </mx:arguments>
      </mx:method>
      </mx:RemoteObject>

      <mx:Panel label="" height="100%" width="100%"
      paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5" cornerRadius="10" roundedBottomCorners="true">

      <mx:HBox width="100%">
      <mx:ComboBox id="repfilter" dataProvider="{newReps}" labelField="label"
      change="{qDollars2.Dollars2(repfilter.selectedItem.data)}" width="150" />
      </mx:HBox>

      <mx:VBox height="100%" >
      <mx:DataGrid dataProvider="{dp}" width="100%" height="50%">
      <mx:columns>
      <mx:DataGridColumn dataField="YDSTYP" headerText="Type" width="180"/>
      <mx:DataGridColumn dataField="YDSDLY" headerText="Dly Sales" minWidth="75" textAlign="right"/>
      <mx:DataGridColumn dataField="YDSCOF" headerText="Cur Off" minWidth="75" textAlign="right"/>
      <mx:DataGridColumn dataField="YDSCON" headerText="Cur On" minWidth="75" textAlign="right"/>
      <mx:DataGridColumn dataField="YDSCTO" headerText="Cur On/Off" minWidth="75" textAlign="right"/>
      <mx:DataGridColumn dataField="YDSLTO" headerText="LY On/Off" minWidth="75" textAlign="right"/>
      <mx:DataGridColumn dataField="Dollars" headerText="% of Sale" minWidth="75" textAlign="right"/>
      <mx:DataGridColumn dataField="YDSCYT" headerText="Cur YTD On/Off" minWidth="115" textAlign="right"/>
      <mx:DataGridColumn dataField="YDSLYT" headerText="LY YTD On/Off" minWidth="115" textAlign="right"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:VBox>

      </mx:Panel>
      </mx:Application>


      Thanks
      George