16 Replies Latest reply on Aug 9, 2007 5:39 PM by GeorgeWS

    Datagrid and FormItem

    GeorgeWS Level 1
      I have a datagrid and a few formitems. I have this that goed to a CFC function that updates a db table:

      private function sendFormdata():void {
      var myobj:Object = new Object();
      myobj.dba = dba.selectedLabel;
      myobj.rep = rep.text;
      myobj.itemid = itemid.text;
      myobj.item = item.selectedLabel;
      myobj.timing = timing.text;
      myobj.programtype = programtype.selectedLabel;
      myobj.status = status.selectedLabel;
      myobj.priority = priority.selectedLabel;
      myobj.descrip = descrip.text;
      myobj.followup = followup.selected;
      myobj.trackcomp = trackcomp.selected;
      myobj.preslocal = preslocal.selected;
      myobj.tracksales = tracksales.selected;
      myobj.followdates = followdates.text;
      cfdataInsert.addData({user:myobj})
      }

      So when I fill out the form elements the data updates.
      My problem is...
      How do I add the values from a datagrid to that part above?

      so fill in a few records in the datagrid then fill in the form elements. and press submit

      Any Thought?

      Thanks
      George
        • 1. Re: Datagrid and FormItem
          ntsiii Level 3
          Is there a set of form data values associated with each dataProvider item?

          Or asking another way, what would the final submitted data look like?

          Tracy
          • 2. Re: Datagrid and FormItem
            GeorgeWS Level 1
            Yes, form fields and the data from the datagrid. So the final data would look something like:

            DBA0(dg), Address0(dg), Zip0(dg), Program(form), status(form)
            DBA1(dg), Address1(dg), Zip1(dg), Program(form), status(form)
            DBA2(dg), Address2(dg), Zip2(dg), Program(form), status(form)

            The DBA, Address, Zip are from the datagrid. The Program, status are from the form firelds. So the form fields get attached to each datagrid record.

            Thanks

            George
            • 3. Re: Datagrid and FormItem
              ntsiii Level 3
              So the same values, from the form, need to be appended to each item in the dataProvider?
              Tracy
              • 4. Re: Datagrid and FormItem
                GeorgeWS Level 1
                Yes exactly.

                George
                • 5. Re: Datagrid and FormItem
                  ntsiii Level 3
                  Loop over the dataProvider.

                  If the items are dynamic (like XML or mx:Object) just add them directly to the items. If not, create a new Object, or xml, or custom object with the required properties.

                  Send that to the server using your normal methodology.

                  Tracy
                  • 6. Re: Datagrid and FormItem
                    GeorgeWS Level 1
                    Ah, so painful...
                    I look all over the internet about the mx:Object and there is hardly anything (I see a close blurp on the livedocs that kinda related to the datagrid but unclear). I understand what you are saying Tracy about the looping over and making a new object , but I cannot get the syntax. I see nothing simple like what I want to do. I am very familiar with the cfdatagrid from CF and updating that. In the CFM there is an UPDATE and has a [ROW] thing going on, simple. Thanks for the tips though

                    George
                    • 7. Re: Datagrid and FormItem
                      ntsiii Level 3
                      Post the loop code and I will show you how to build an XML object to send to the server.

                      Tracy
                      • 8. Re: Datagrid and FormItem
                        GeorgeWS Level 1
                        I think its something like this:
                        for (var i:int = 0; i < myAccounts.length; i++ ) {
                        var aAccounts:Account = myAccounts ;
                        cfdataInsert.update( aAccounts ) ;

                        }

                        Thanks alot Tracy, I know Im a pain...

                        myAccounts is the name of the dataProvider for the datagrid.

                        This is the RO that sends the data to the CFC to get inserted into a table. (currently only working with the fields used in sendFormdata Function, that is shown in the original post)

                        <mx:RemoteObject
                        id="cfdataInsert" showBusyCursor="true"
                        destination="ColdFusion"
                        source="youngsmarket.programs.national.nataccpro.bin.nataccpro">
                        <mx:method name="update" result="handleUpdateResult(event)" fault="Alert.show(event.fault.message)"/>
                        </mx:RemoteObject>
                        • 9. Re: Datagrid and FormItem
                          ntsiii Level 3
                          Assuming "Account" is a dynamic object:

                          var oAccount:Account;
                          for (var i:int = 0; i < myAccounts.length; i++ ) {
                          oAccount = myAccounts [ i ] ;
                          if (oAccount .checked == true ) { //is item selected
                          oAccount["rep"] = rep.text; //if Account is not dynamic, then you can hard code the properties in it
                          ...
                          }

                          }

                          Tracy
                          • 10. Re: Datagrid and FormItem
                            GeorgeWS Level 1
                            So I just add your code to my "update" function?

                            I think I blew it when I sent you what I has so far. The "Account" is the RO method? My RO method is called Accounts.
                            Also "rep" is that supposed to be a column in my datagrid? I have "Include" for my checkbox field in the datagrid (is include a reserved word). So I did this:

                            private function update():void {
                            var myobj:Object = new Object();
                            myobj.dba = dba.selectedLabel;
                            myobj.itemid = itemid.text;
                            myobj.item = item.selectedLabel;
                            myobj.programtype = programtype.selectedLabel;
                            myobj.status = status.selectedLabel;
                            myobj.priority = priority.selectedLabel;
                            myobj.descrip = descrip.text;
                            myobj.followup = followup.selected;
                            myobj.trackcomp = trackcomp.selected;
                            myobj.preslocal = preslocal.selected;
                            myobj.tracksales = tracksales.selected;
                            myobj.startdate = startdate.selectedDate;
                            myobj.enddate = enddate.selectedDate;
                            myobj.followdates = followdates.selectedDate;
                            cfdataInsert.addData({user:myobj})
                            var oAccount:Accounts;
                            for (var i:int = 0; i < myAccounts.length; i++ ) {
                            oAccount = myAccounts [ i ] ;
                            if (oAccount .checked == true ) { //is item selected
                            oAccount["Include"] = Include.text; //if Account is not dynamic, then you can hard code the properties in it
                            }
                            }
                            }

                            I feel like Im close. Thanks

                            George
                            • 11. Re: Datagrid and FormItem
                              ntsiii Level 3
                              Generally, what we are doing is looping over the dataProvider, checking the value of the include (that might be a dangerous name), and if it is true, we are setting propertie in the dataProvider item to the value in the form.

                              What is the dataProvider, anyway?

                              Tracy
                              • 12. Re: Datagrid and FormItem
                                GeorgeWS Level 1
                                Tracy,
                                This is my RemoteObject:

                                <mx:RemoteObject
                                id="Accounts"
                                destination="ColdFusion"
                                source="youngsmarket.programs.national.nataccpro.bin.nataccpro"
                                showBusyCursor="true" >
                                <mx:method name="Accounts" result="handleAccountsResult(event)" fault="Alert.show(event.fault.message)">
                                <mx:arguments>
                                <supcomp>{SupComp}</supcomp>
                                <supplierid>{SupplierID}</supplierid>
                                </mx:arguments>
                                </mx:method>
                                </mx:RemoteObject>

                                This is the function that handles the result of the RO above.

                                [Bindable] public var myAccounts:ArrayCollection;

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

                                So in the DataGrid the Dataprovider is myAccounts.

                                Thanks for helping me. I really cannot do it unless I see samples. I have been looking for a week all day and all night I have read just about every blog and every related post on here, I also have books but no answers. What does that looping over the dataprovider look like and how will I append the info from the form fields?

                                Thanks again
                                George
                                • 13. Re: Datagrid and FormItem
                                  ntsiii Level 3
                                  "What does that looping over the dataprovider look like " That is what we just did a couple posts back.

                                  Ok, the dataProvider is an ArrayCollection of WHAT? What kind of objects? Are they dynamic?

                                  How are you going to send the data back to the server? What kind of data structure. If it is xml i can help, if not you are on your own with the sending handleing part. I can help you build the structure.

                                  Also, please stop re-posting the same question. The most recent is about the fourth time you have asked the same thing. Repeated posting won't help, particularly when you have someone trying to help.

                                  Tracy
                                  • 14. Re: Datagrid and FormItem
                                    GeorgeWS Level 1
                                    Hum...
                                    Im more baffled then before. Im thinking Flex and ColdFusion cant do what I want. Even though I could do it in ColdFusion alone using the CFGRID, but that has its own issues.
                                    I dont know what else to put. You asked...
                                    "Ok, the dataProvider is an ArrayCollection of WHAT? What kind of objects? Are they dynamic?"
                                    The dataProvider is an ArrayCollection from the RemoteObject that gets called when the app opens (creationComplete). The ArrayCollection has fields in it like DBA, Address, City, Zip. These addresses come from a table on my SQL server. As to What kind of object I do not know; and if they are dynamic, I dont know what you mean.

                                    Then you asked:
                                    How are you going to send the data back to the server? What kind of data structure. If it is xml i can help, if not you are on your own with the sending handleing part. I can help you build the structure.

                                    I showed you my RO that uses the function sendFormdata form fields (this works). As to what kind of data structure? I think I have said it is an arraycollection from a remote object a few times. Im using Cold Fusion 7

                                    I post multiple times to see if anyone has other takes on what I want to do. We have posted back and forth for a week and I have gotten know where. I ask questions and you ask me more questions.

                                    Thanks Anyways
                                    • 15. Re: Datagrid and FormItem
                                      ntsiii Level 3
                                      "What kind of object I do not know; and if they are dynamic, I dont know what you mean. " You need to learn this.

                                      You have not posted "function sendFormdata " code. Perhaps it is the key

                                      The RemoteObject code is of no use to me. I need to know the format of the data that is being sent to the server, the Flex/AS data structure. We must know this in order to add data to it or to build a new structure with the combind data from the DG and the form.

                                      I will not be able to help unless you can answer my questions.

                                      Tracy
                                      • 16. Re: Datagrid and FormItem
                                        GeorgeWS Level 1
                                        This is what I have for my sendFormdata function. This part works (I fill in/select from components that fill in the fields in the function when I press a send button) going to a RO and off to a CFC for insert to a table. The table has the same field names as each field below. dba, itemid, item, timing etc.
                                        PLUS fields for each column in the datagrid: cust, seq, address, city, zip, phone

                                        private function sendFormdata():void {
                                        var myobj:Object = new Object();
                                        myobj.dba = dba.selectedLabel;
                                        myobj.itemid = itemid.text;
                                        myobj.item = item.selectedLabel;
                                        myobj.timing = timing.text;
                                        myobj.programtype = programtype.selectedLabel;
                                        myobj.status = status.selectedLabel;
                                        myobj.priority = priority.selectedLabel;
                                        myobj.descrip = descrip.text;
                                        myobj.followup = followup.selected;
                                        myobj.trackcomp = trackcomp.selected;
                                        myobj.preslocal = preslocal.selected;
                                        myobj.tracksales = tracksales.selected;
                                        myobj.followdates = followdates.text;
                                        cfdataInsert.addData({user:myobj})
                                        }