4 Replies Latest reply on Nov 30, 2006 12:58 PM by GeorgeWS

    DataGrid and ComboBox

    GeorgeWS Level 1
      I have a grid that gets filled with an Array called myDollars from a RemoteObject called qDollars :

      <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>

      This is the GRID:

      <mx:DataGrid dataProvider="{myBrand}" width="981" height="100%">
      <mx:columns>
      <mx:DataGridColumn visible="false" dataField="ydspno"/>
      <mx:DataGridColumn dataField="ydspna" headerText="Supplier" width="225"/>
      <mx:DataGridColumn dataField="ydscna" headerText="Brand" width="225"/>
      <mx:DataGridColumn dataField="ydscqt" headerText="Sales" minWidth="150" textAlign="right"/>
      <mx:DataGridColumn dataField="ydscac" headerText="Accounts" minWidth="150" textAlign="right"/>
      <mx:DataGridColumn dataField="ydslqt" headerText="LYM" minWidth="150" textAlign="right"/>
      <mx:DataGridColumn dataField="ydslac" headerText="LYAccounts" minWidth="150" textAlign="right"/>
      </mx:columns>
      </mx:DataGrid>

      The CFC is like this:

      <cffunction name="Brands" access="remote" returnType="query" output="false">
      <cfargument name="employee" required="no">
      <cfargument name="supcomp" required="no">
      <CFQUERY DATASOURCE="Coredata" NAME="Brands">
      SELECT ydspna, ydspno, ydscna, SUM(ydscqt) AS ydscqt, SUM(ydscac) AS ydscac, SUM(ydslqt) AS ydslqt, SUM(ydslac) AS ydslac
      <cfif #SupComp# IS 'YY'>
      FROM tblYMFSWDSL
      </cfif>
      <cfif #SupComp# IS 'YA'>
      FROM tblYAFSWDSL
      </cfif>
      <cfif #SupComp# IS 'BL'>
      FROM tblBLFSWDSL
      </cfif>
      WHERE YDSNNO = '#Employee#'
      GROUP BY ydspna, ydspno, ydscna
      ORDER BY ydspna, ydscna
      </CFQUERY>
      <cfreturn Brands>
      </cffunction>

      That part works fine. The data is summed in the cfc. The summed data shows when the user logs in. I also have a combobox filled with an Array called newReps from a RemoteObject called Reps.

      This is the 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>

      This is the ComboBox:

      <mx:ComboBox id="repfilter" dataProvider="{newReps}" labelField="label" width="150" />

      The ComboBox gets filled just fine. I want the first selection in the combo box that I have set to "Select Rep" using the following function:
      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;
      }

      So in short I want the grid to initially fill with the summary data (got that). Then when a rep from the combobox is selected the data changes to the reps data. This would be another cffunction in the CFC, and then change back to summary data when "Select Rep" is selected. Im not sure how to fill the datagrid from 2 different cffunctions one bing the summar and the other being all. Any thoughts?

      Thanks
      George



        • 1. Re: DataGrid and ComboBox
          ntsiii Level 3
          Assuming I am analyzing your code right:

          Give the DataGrid an id, say id="dgBrand".
          then in doPrompt2(), do:
          dgBrand.dataProvider = newReps;

          This assumes doPrompt2 assigns the result data to the newReps variable.

          Tracy
          • 2. Re: DataGrid and ComboBox
            GeorgeWS Level 1
            Tracy,
            I am very very close. Thanks for your help. I copied my grid so that there are 2 one call an array: myData that fills in when I first open the app. It looks like:
            <mx:DataGrid dataProvider="{myData}" initialize="qResult.Achievements()">
            (this part works good)

            The 2nd grid I put the id="dgBrand" so its like:
            <mx:DataGrid id="dgBrand" dataProvider="{AllData}" >
            This one is blank when I enter the app. When I select a person from the combobox is gets the data from the RemoteObject and fills in the grid with the data and when I cange the name it gets that persons data and when I select the default from the combobox it blanks the grid. (Very Cool) So all is perfect except I want to put then in the same grid. Im thinking the dataprovider needs to be a variable so it can change between {myData} and {AllData}. But I dont know how this would look.

            Thanks
            George
            • 3. Re: DataGrid and ComboBox
              ntsiii Level 3
              I am not quite following you. Tell me what the data is, when it loads, and how you want to display it.

              Tracy

              • 4. Re: DataGrid and ComboBox
                GeorgeWS Level 1
                Tracy,
                This is a stripped down version of my app.

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

                [Bindable]
                public var myData:ArrayCollection;


                [Bindable]
                public var Employee:String;

                [Bindable]
                public var SupComp:String;

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

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


                public function handleQueryResult3(event:ResultEvent):void{
                myData=event.result as ArrayCollection;

                }


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

                }

                public function handleQueryResult5(event:ResultEvent):void{
                AllData=event.result as ArrayCollection;

                }



                [Bindable]
                public var selectedItem:Object;

                public function initVars() : void {
                Employee = Application.application.parameters.Employee;
                SupComp = Application.application.parameters.SupComp;
                qResult.Achievements(Employee, SupComp);
                Reps.Reps.send();
                qData.AllReps(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;
                }

                ]]>
                </mx:Script>



                <mx:RemoteObject
                id="qResult"
                destination="ColdFusion"
                source="youngsmarket.programs.sales.salesdm.bin.salesdm"
                showBusyCursor="true" >
                <mx:method name="Achievements" result="handleQueryResult3(event)" fault="Alert.show(event.fault.message)">
                <mx:arguments>
                <employee>{Employee}</employee>
                <supcomp>{SupComp}</supcomp>
                </mx:arguments>
                </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:RemoteObject
                id="qData"
                destination="ColdFusion"
                source="youngsmarket.programs.sales.salesdm.bin.salesdm"
                showBusyCursor="true" >
                <mx:method name="AllReps" result="handleQueryResult5(event)" fault="Alert.show(event.fault.message)">

                </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="{qData.AllReps(repfilter.selectedItem.data)}" width="150" />

                </mx:HBox>
                <mx:Accordion id="accordion" width="100%" height="100%" headerHeight="5">
                <mx:VBox height="100%" >
                <mx:DataGrid id="dgReps" dataProvider="{myData}" initialize="qResult.Achievements()" width="100%" height="50%">
                <mx:columns>

                <mx:DataGridColumn dataField="BRNM36" headerText="Brands" minWidth="150"/>
                <mx:DataGridColumn dataField="Period" headerText="Period" minWidth="75" />
                <mx:DataGridColumn dataField="GOCS36" headerText="Case Goal" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="TotalSales" headerText="Sales" minWidth="26" textAlign="right"/>
                <mx:DataGridColumn dataField="Goal" headerText="% Goal" minWidth="26" textAlign="right"/>
                <mx:DataGridColumn dataField="LYCS36" headerText="LY Sales" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="GOAC36" headerText="Acc Goal" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="TotalAcc" headerText="Accounts" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="GoalAcc" headerText="% Goal" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="LYAC36" headerText="LY Accounts" minWidth="50" textAlign="right"/>
                </mx:columns>
                </mx:DataGrid>
                <mx:DataGrid id="dgReps2" dataProvider="{AllData}" width="100%" height="50%">
                <mx:columns>

                <mx:DataGridColumn dataField="BRNM36" headerText="Brands" minWidth="150"/>
                <mx:DataGridColumn dataField="Period" headerText="Period" minWidth="75" />
                <mx:DataGridColumn dataField="GOCS36" headerText="Case Goal" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="TotalSales" headerText="Sales" minWidth="26" textAlign="right"/>
                <mx:DataGridColumn dataField="Goal" headerText="% Goal" minWidth="26" textAlign="right"/>
                <mx:DataGridColumn dataField="LYCS36" headerText="LY Sales" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="GOAC36" headerText="Acc Goal" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="TotalAcc" headerText="Accounts" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="GoalAcc" headerText="% Goal" minWidth="50" textAlign="right"/>
                <mx:DataGridColumn dataField="LYAC36" headerText="LY Accounts" minWidth="50" textAlign="right"/>
                </mx:columns>
                </mx:DataGrid>
                </mx:VBox>
                </mx:Application>

                So what I have here is the first grid (qResult - myData is the Array from the qResult RO) gets filled when the app loads.
                The second grid (qData - AllData is the Array from the qData RO) is blank when loaded. When I select a rep from the combobox the second grid is filled with that pesons data. and when I put the combobox back to its default "Select Rep" the second grid goes blank again. This is all good if it where in one grid.

                What I want to happen is to have only ONE grid, that gets filled with the data from qResult upon load and after a selection has been made to the Combo Box and then put back to "Select Rep", so the default would be qResult. When a selection is made in the combobox the grid is repopulated with qData. In short the Managers sees his totals then can select one of the team members from the combobox and see thier data, then back to the managers view if the combobox is set back to "Select Rep"

                Hope this makes sence, I feel like I am right there. Thanks for the help

                George