4 Replies Latest reply on Dec 28, 2010 9:48 PM by kiran7881

    Combo box and Datagrid connection

    willise414 Level 1

      Hi there,

       

      Fairly new to Flex and Actionscript so I apologize if this question seems a little silly:)

       

      I have a database that contains employees and each employee is assigned a different department, for example.

       

      So I created a Flex app that has a combo box. The application retrieves all of the departments from the database and displays them in the drop down combo box. That part is working fine. Now what I want to do is have a list of employees appear in the datagrid when a specific department is selected in the combo box.

       

      Foe example, if I select Managers from the combo box. the datagrid should populate with all of the managers. If I select Admin Staff, all the admin employees should show up.

       

      I know this is probably very simple, but I can't figure it out.

       

      Thanks a million!!!!

        • 1. Re: Combo box and Datagrid connection
          Gregory Lafrance Level 6

          Your best bet is to use the selected value of the ComboBox to make a data call to get employees of that dept, and use the returned data to populate the DG.

           

          If this post answers your question or helps, please mark it as such. Thanks!

          http://www.chikaradev.com
          Adobe Flex Development and Support Services

          1 person found this helpful
          • 2. Re: Combo box and Datagrid connection
            willise414 Level 1

            Thanks for the reply.

             

            I understand what you are saying and I agree that that is what needs to happen, but that is my problem.

             

            How do I code that?

             

            Thanks!!

            • 3. Re: Combo box and Datagrid connection
              Gregory Lafrance Level 6

              This code should work, though I did not try this out as it makes a data call:

               

              <?xml version="1.0"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                creationComplete="init();">
                <mx:Script><![CDATA[
                  import mx.collections.XMLListCollection;
                  import mx.rpc.events.ResultEvent;
                  import mx.collections.ArrayCollection;
                  
                  [Bindable] private var depts:ArrayCollection = 
                    new ArrayCollection(["finance", "human resources", "marketing"]);
                    
                  [Bindable] private var ees:XMLListCollection = new XMLListCollection();
                  
                  private function sendRequest():void{
                    var params:Object = new Object();
                    params.dept = myCmbx.selectedLabel;
                    dataSvc.send(params);
                  }
                  
                  private function resultHandler(evt:ResultEvent):void{
                    ees = new XMLListCollection(evt.result.employees);      
                  }
                ]]></mx:Script>
                <mx:HTTPService id="dataSvc" resultFormat="e4x"
                  result="resultHandler(event)" url="myPhpScript.php"/>
                <mx:ComboBox id="myCmbx" dataProvider="{depts}" change="sendRequest()"/>
                <mx:DataGrid dataProvider="{ees}">
                  <mx:columns>
                    <mx:DataGridColumn dataField="name"/>
                    <mx:DataGridColumn dataField="age"/>
                    <mx:DataGridColumn dataField="dept" width="130"/>
                  </mx:columns>
                </mx:DataGrid>
              </mx:Application>
              


              The PHP script should get the dept value and return xml.

               

              If this post answers your question or helps, please mark it as such. Thanks!

              http://www.chikaradev.com
              Adobe Flex Development and Support Services

              • 4. Re: Combo box and Datagrid connection
                kiran7881 Level 1

                Sincerly applogize for not starting a new Thread and continuing with my question in this Thread itself .

                 

                I have a similar requirement , where depending on the Search  Button Click  , i need to show all the Employees matching that Name .

                 

                I am able to display the Names and depertments of those Employess matching to the Search  on to the Datagrid , but i also need to show the Picture of the Employee (Please suggest me as how to dynamically display the Picture ??)

                 

                Please suggets , thanks .