8 Replies Latest reply on Nov 14, 2006 10:45 AM by ntsiii

    Accessing a datagrid's column

    africanshox
      this is for a small mailing application that I'm working on. the app initialises by populating a datagrid with rows from a data base with columns titled, name, email address and location.

      a second empty datagrid acts as a destination for dragged items from the first datagrid. underneath that is a small form that will allow the user to enter a message and subject.

      when the user clicks the send button i would like only the email address column to be passed over to phpmailer as an array in order to send emails to the users on that datagrid...so how can one extract only certain columsn from a datagrid.....thanks in advance
        • 1. Re: Accessing a datagrid's column
          chris.huston.t10 Level 3
          You access the email column by referring to your datagrid's dataProvider's email property. So if the property is 'email' then:

          var user_email:String = datagrid.selectedItem.email;

          Vygo
          • 2. Re: Accessing a datagrid's column
            africanshox Level 1
            thanks ...however wouldnt that only apply to the selected item on the grid rather than all the email items on the grid.

            the purpose for this would be if i wanted the application user to send one email to all the users on the datagrid.
            • 3. Re: Accessing a datagrid's column
              africanshox Level 1
              ive been told on flexcoders that this feature is currently not available and the best way would be to loop through the data provider and store the contents of the entire column in an array. as i am relatively new to flex does anyone know how i could go about doing this?
              • 4. Re: Accessing a datagrid's column
                ntsiii Level 3
                Sure, that was me on flexcoders and I hang out here as well.

                What is the format of your dataProvider?

                Tracy
                • 5. Re: Accessing a datagrid's column
                  africanshox Level 1
                  the data provider is an array of results from a database. this is used to populate the first datagrid. i then drag the results to the second datagrid. now i want an email message sent to all the items(users with email addresses) on the second datagrid.
                  here's the code for the datagrids:

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApplication()">
                  <mx:DataGrid dataProvider="{infoProvider}" id="srclist" x="10" y="120" dragEnabled="true" allowMultipleSelection="true" width="452">
                  <mx:columns>
                  <mx:DataGridColumn headerText="Name" dataField="gname"/>
                  <mx:DataGridColumn headerText="Email" dataField="gmail"/>
                  <mx:DataGridColumn headerText="From" dataField="gfrom"/>
                  </mx:columns>
                  </mx:DataGrid>

                  <mx:DataGrid id="destlist" x="496" y="120" dropEnabled="true" width="500">
                  <mx:columns>
                  <mx:DataGridColumn headerText="Name" dataField="gname"/>
                  <mx:DataGridColumn headerText="Email" dataField="gmail"/>
                  <mx:DataGridColumn headerText="From" dataField="gfrom"/>
                  </mx:columns>
                  </mx:DataGrid>

                  <mx:Script>
                  <![CDATA[
                  import mx.controls.Alert;
                  [Bindable]
                  public var infoProvider:Array;
                  import flash.net.Responder;
                  public var gateway:RemotingConnection;
                  public var response:Responder;
                  public var user_email:Array
                  public var gatewayURL:String = " http://localhost/flashservices/gateway.php";
                  public function initApplication():void{

                  srclist.dataProvider = [infoProvider];//data grid source
                  destlist.dataProvider = []; //destination of dragged items
                  response = new Responder(onResult,onFault);
                  gateway = new RemotingConnection(gatewayURL);
                  gateway.call( "service.viewPosters", response);

                  }
                  public function onResult( result : Array ) : void
                  {
                  infoProvider = result;
                  }
                  public function onFault( fault : String ) : void
                  {
                  trace( fault );
                  }
                  public function sendMail(params:Array,params2:Array):void{
                  response = new Responder(onSendResult,onSendFault);
                  gateway = new RemotingConnection(gatewayURL);
                  gateway.call('email.sendMail',response,params,params2);

                  }

                  public function onSendResult( result : String ) : void{

                  Alert.show(result);
                  }
                  public function onSendFault( fault : String ) : void
                  {
                  Alert.show(fault);
                  }

                  ]]>
                  </mx:Script>
                  <mx:Label x="10" y="94" text="Database list" width="101"/>
                  <mx:Label x="496" y="94" text="Email list" width="134"/>
                  <mx:Form x="10" y="275" width="452" height="371">
                  <mx:FormItem label="Subject:">
                  <mx:TextInput width="338" id="subject"/>
                  </mx:FormItem>
                  <mx:FormItem>
                  <mx:TextArea width="337" height="214" id="msg"/>
                  </mx:FormItem>

                  <mx:Button label="Send" click="sendMail([subject.text,msg.text],[destlist.])" />
                  </mx:Form>
                  </mx:Application>


                  • 6. Re: Accessing a datagrid's column
                    ntsiii Level 3
                    var aEmails:Array = new Array();
                    for (var i:int=0;i<infoProvider.length;i++) {
                    aEmails.push(infoProvider[ i ].gmail)
                    }

                    Tracy
                    • 7. Accessing a datagrid's column
                      africanshox Level 1
                      hi i've tried putting in the code as suggested but the mail function does not seem to work can you please look at my coe and tell me what im doing wrong? thank you pay close attention to the send button at the bottom of the page...im i using the right variable"aEmails"?

                      <?xml version="1.0" encoding="utf-8"?>
                      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApplication()">
                      <mx:DataGrid dataProvider="{infoProvider}" id="srclist" x="10" y="120" dragEnabled="true" allowMultipleSelection="true" width="452">
                      <mx:columns>
                      <mx:DataGridColumn headerText="Name" dataField="gname"/>
                      <mx:DataGridColumn headerText="Email" dataField="gmail"/>
                      <mx:DataGridColumn headerText="From" dataField="gfrom"/>
                      </mx:columns>
                      </mx:DataGrid>

                      <mx:DataGrid id="destlist" x="496" y="120" dropEnabled="true" width="500">
                      <mx:columns>
                      <mx:DataGridColumn headerText="Name" dataField="gname"/>
                      <mx:DataGridColumn headerText="Email" dataField="gmail"/>
                      <mx:DataGridColumn headerText="From" dataField="gfrom"/>
                      </mx:columns>
                      </mx:DataGrid>



                      <mx:Script>
                      <![CDATA[
                      import mx.controls.Alert;
                      [Bindable]
                      public var infoProvider:Array;

                      public var aEmails:Array;
                      import flash.net.Responder;
                      public var gateway:RemotingConnection;
                      public var response:Responder;
                      public var gatewayURL:String = " http://localhost/flashservices/gateway.php";



                      public function initApplication():void{

                      srclist.dataProvider = [infoProvider];//data grid source
                      destlist.dataProvider = []; //destination of dragged items
                      response = new Responder(onResult,onFault);
                      gateway = new RemotingConnection(gatewayURL);
                      gateway.call( "service.viewPosters", response);




                      }
                      public function onResult( result : Array ) : void
                      {
                      infoProvider = result;

                      var aEmails:Array = new Array();
                      for (var i:int=0;i<infoProvider.length;i++) {
                      aEmails.push(infoProvider[ i ].gmail)
                      }
                      }
                      public function onFault( fault : String ) : void
                      {
                      trace( fault );
                      }


                      public function sendMail(params:Array,params2:Array):void{
                      response = new Responder(onSendResult,onSendFault);
                      gateway = new RemotingConnection(gatewayURL);
                      gateway.call('email.sendMail',response,params,params2);


                      }

                      public function onSendResult( result : String ) : void{

                      Alert.show(result);
                      }
                      public function onSendFault( fault : String ) : void
                      {
                      Alert.show(fault);
                      }





                      ]]>
                      </mx:Script>
                      <mx:Label x="10" y="94" text="Database list" width="101"/>
                      <mx:Label x="496" y="94" text="Email list" width="134"/>
                      <mx:Form x="10" y="275" width="452" height="371">
                      <mx:FormItem label="Subject:">
                      <mx:TextInput width="338" id="subject"/>
                      </mx:FormItem>
                      <mx:FormItem>
                      <mx:TextArea width="337" height="214" id="msg"/>
                      </mx:FormItem>

                      <mx:Button label="Send" click="sendMail([subject.text,msg.text],[aEmails])" />


                      </mx:Form>

                      </mx:Application>
                      • 8. Re: Accessing a datagrid's column
                        ntsiii Level 3
                        The problem is you re-declared aEmails inside the onResult() function which makes it local to that function. Remove the declaration in onREsult and just set it to new Array() there.

                        Tracy