6 Replies Latest reply on Dec 5, 2006 3:27 PM by GeorgeWS

    Changing the DataProvider

    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. this works fine. I want to select a name from the combobox and it change the grids dataProvider. I am close but not perfect. The grid initially fills fine the way it is bellow. But when I select a name nothing happens. If I change the dataProvider from "dp" to "myDollars2" the combobox works when I change the names, but the initial data from myDollars does not show.

      <?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 myData:ArrayCollection;

      [Bindable]
      public var myDollar:ArrayCollection;

      [Bindable]
      public var myDollar2:ArrayCollection;

      [Bindable]
      public var Employee:String;

      [Bindable]
      public var SupComp: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;
      dgReps2.dataProvider = qData;

      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
        • 1. Re: Changing the DataProvider
          GeorgeWS Level 1
          This seems so easy but I just cant get it to work right. Can anyone help?
          • 2. Re: Changing the DataProvider
            ntsiii Level 3
            George, as I asked before, please explain your app in words. I really am not willing to analyze the code to understand what the data is, when it loads, and how you want to display it..

            Tracy
            • 3. Re: Changing the DataProvider
              GeorgeWS Level 1
              I have a RemoteObject that fills in a ComboBox. The ComboBox has people that work on a team. A manger logs in and I pass his employee number into the application. So I want the default of the combobox to be the manager. When the application starts a grid is filled with the managers data. Then the manager can select a person and the data changes to that persons data. Then when the ComboBox is put back to the default position fill back in the table with the original manager data.

              Thanks for helping me
              George
              • 4. Re: Changing the DataProvider
                ntsiii Level 3
                Then I think you are over-complicating this.
                on initialize:
                * call Reps.Reps()
                * in the Reps result handler, set the selected item to the manager and set Employee and SUComp values to the manager, then invoke qDollars.Dollars
                * in the qDollars result handler set the "dp" variable

                The manager data will display in the dataGrid.

                In the change event handler of the ComboBox, set Employee and SUComp values to the values in the selectedItem, then invoke qDollars.Dollars.

                That should do it if I understand correctly

                Tracy
                • 5. Re: Changing the DataProvider
                  GeorgeWS Level 1
                  I dont see how that works. Where is the call to the remoteObject getting the individual Reps? Im also really unsure of how to write the 2nd part for the Reps result handler. Also I dont know what the change event would look like. Are there samples of this anywhere? I see stuff thats close on feedsquirrel and forta but not quite the same. I really need a sample.

                  Thanks George
                  • 6. Re: Changing the DataProvider
                    GeorgeWS Level 1
                    Thanks for your help Tracy. I got it!