18 Replies Latest reply on Aug 1, 2007 2:29 PM by AndyWW

    Datagrid in a form

    GeorgeWS Level 1
      I have a remote object, and an array that is used to fill a datagrid with info (myAccounts), one of the columns is a checkbox (include is the column name). I want to check some of the boxes and press send and have those records be added to a DB. How do you do this?

      Thanks
      George
        • 1. Re: Datagrid in a form
          ntsiii Level 3
          The checkbox must update a property in the dataProvider.

          When you are ready, loop over the dataProvider, inspect the values of the "include" property, and if true, add that item to the structure you are going to pass back to the server.

          Tracy
          • 2. Re: Datagrid in a form
            GeorgeWS Level 1
            Tracey, you have rescued me so many times... I have an array that fill's the DataGrid; and a bunch of form fields that I want to attach to the send of the selections from the datagrid.Tthe form fields work fine i want to know how to update/add records that have a selections from the grid (say 5 selected accounts) and each account would have the form data and the grid data. I just dont know how to select a check box in a grid and have them loop over the detail part and add a record for each account selected in the grid. So each selection has that grid info + form info

            Thanks
            George
            • 3. Re: Datagrid in a form
              ntsiii Level 3
              Do you already have the checkBox item renderer? And does do this? "The checkbox must update a property in the dataProvider."

              That is the main step. When that is happening, the rest will be easy.

              Tracy
              • 4. Re: Datagrid in a form
                GeorgeWS Level 1
                I do have the checkbox show in the grid but if you check it; it does nothing. You can see it here:

                http://www.youngsmarket.com/youngsmarket/programs/national/nataccpro/bin/NatAccPro.cfm?Sup plierID=30

                If I set the form items the app added a record to a db. But cant seem to get the checked accounts from the grid to get added to the db. I seem some samples that are kinda close but not that close. Can you lead me to a sample?

                Thanks again
                George
                • 6. Re: Datagrid in a form
                  GeorgeWS Level 1
                  Still stumped. I do see samples about the checkbox, and how to use an item renderer. Im pretty sure I can do that part. But I cant figure out how to have the Checked datagrid elements get added to a DB along with the form items added to each record from the datagrid. I am using The remote object to get my ArrayCollection for the Datagrid. I reposted my link with a View Source. Im thinking if I got the Add/Update part where I sent a datagridcolumn (that has a true or false) along with the form element I might get further. Maybe my biggest problem is pushing the datagrid back to the SQL Server.

                  http://www.youngsmarket.com/youngsmarket/programs/national/nataccpro/bin/srcview/index.htm l

                  Thanks for looking
                  George
                  • 7. Re: Datagrid in a form
                    ntsiii Level 3
                    If your itemRenderer is updating the dataProvider, then you can simply loop over the dataProvider, checking for a "true" value in the "selected" property.

                    When you have an item that is selected, add the properties form the form to it, then put it in a collection of some kind (use XML, it is dynamic and you can add attributes at will).

                    When you are done looping, send the XML to the server, parse the xml and do the database update.

                    Tracy
                    • 8. Re: Datagrid in a form
                      GeorgeWS Level 1
                      Tracy,
                      I do not know if my check box is updaing the dataprovider. I dont want to use XML; I like ArrayCollection and RemoteObject (sorry Im picky like that).
                      Isnt there a sample.

                      RemoteObject to ArrayCollection To Datagrid-
                      Changes made to grid data and some form fileds filled out-
                      SUBMIT
                      Add to DB table each grid row with form fields?

                      So Im not sure how to simply or easily do anything.

                      Please please please help me with a sample. Im sure a few lines that I dont know into my code would make it work.

                      Thanks
                      George
                      • 9. Re: Datagrid in a form
                        GeorgeWS Level 1
                        I need help!!
                        Does anyone have a sample of this. I see lots of questions that are related but no real working answer?

                        Thanks George
                        • 10. Re: Datagrid in a form
                          AndyWW Level 1
                          Are you using Flex Data Services? Or are you coding the database access yourself? Are you using Hibernate on the server side? I have worked with database retrival and update without FDS, and so I may be able to give you pointers if that is what you are doing.

                          Andy
                          • 11. Re: Datagrid in a form
                            GeorgeWS Level 1
                            Andy,
                            Thanks for looking. I am Making call (creationComplete) to a RemoteObject. Then I take the results and put them in an ArrayCollection, that arrayCollection fills a datagrid. Here is what I have:

                            http://www.youngsmarket.com/youngsmarket/programs/national/nataccpro/bin/srcview/index.htm l?SupplierID=30

                            The Checkbox part does not work. If some get checked and I scroll the checks disapear. I have been reading alot about this issue, but still cand find a GOOD solution.

                            Besides the checkbox. If I could update/add the records from the datagrid along with the form fields I might get further.

                            Thanks again

                            George
                            • 12. Re: Datagrid in a form
                              AndyWW Level 1
                              George,

                              I don't know much about the client (AS) side of this, and so I don't think I can help with the checkbox problem. However, if you have not used FDS then I may be able to help with the database updating. Have you written your own Java class on the server side to handle the remote object requests? Or does FDS take care of this for you? I have used AS for almost all of my client-side coding, and so I don't know exactly how that fits with the MXML equivalent. Also, I have only used Tomcat, and not Coldfusion, on the server side. I suspect that the "cfdataInsert.addData({user:myobj})" in your mxml file actually takes care of the communication with the server. But if you have used Java then just let me know!

                              Andy
                              • 13. Re: Datagrid in a form
                                GeorgeWS Level 1
                                Andy,
                                Yes the cfdataInsert is what sends the form fields to the backend (CFC), BUT it does not push the datagrid witht it. Im not worried about the Backend (CFC) that part I have down. Its the AS that I can not figure out how to get both the Datagrid and the Form Fields to get over to the CFC so I can update the table. At this point im so frustrated I just want to see the WHOLE datagrid and fields update a table TOGETHER. Then I will deal with the checkbox and whether its checked or not. Any help would be great. I have been at this for days...

                                Thanks
                                • 14. Re: Datagrid in a form
                                  AndyWW Level 1
                                  George,

                                  I don't want to frustrate you any more, but the reason that I am asking about the server side is that it seems to me that you need to send the data from the grid to the server if you want it to be used to update the database. Did you write the method "cfdataInsert.addData()" in Java? Or is that a library routine provided by Coldfusion? If it is your code then I would expect you to pass an additional parameter from the client, namely, the myAccounts ArrayCollection (since the grid is bound to that object). You can then iterate through the List object that is received in the remote method to update the database based upon the entries in the grid. So ... if you have constructed the SQL statement that inserts the form (non-grid) data, then you can also construct and execute SQL statements for each of the rows in the grid.

                                  Andy
                                  • 15. Re: Datagrid in a form
                                    GeorgeWS Level 1
                                    Andy,
                                    The cfdataInsert is just the ID of my RemoteObject. Its ActionScript. I can tell you understand what I want to do. I want to see how to add the myAccounts ArrayCollection to the sendFormdata function. That is the function that sends all of the form fields. I need to see what the AS sendFormdata function will look like with the myAccounts arraycollection added to it. Do I set each field? If so how? Do I just send the myAccounts arrayCollection all together? What would that look like?

                                    Thanks again
                                    George
                                    • 16. Re: Datagrid in a form
                                      AndyWW Level 1
                                      George,

                                      Sorry, I should have looked at the destination for the RemoteObject, which is "ColdFusion". Is this a class that you wrote in Java? Or is it supplied with the ColdFusion server? If ColdFusion does not link to something that you have written (through the entry in the services-config.xml) then you could probably just loop through the myAccounts ArrayCollection doing the same kind of thing that you have done with the form fields. It appears to me (although I can't be certain because of my unfamiliarity with AS) that there are properties in your collection named "Include", "CAD105", "CAD205", etc., which I assume match column names from the Accounts table. You can loop through the myAccounts collection (using "for (var o: Object in myAccounts) {...}") and call "cfdataInsert.addData()" for each one, after setting myobj.Include equal to o["Include"], myobj.CAD105 = o["CAD105"], etc. Actually, I really don't know how CF links this data back to the correct table from the information that is sent in addData(). And you haven't told me whether you have actually written Java code to handle this!

                                      I'm sorry that I can't be more specific in my replies, but I really don't know your implementation details on the server side.

                                      Andy
                                      • 17. Re: Datagrid in a form
                                        GeorgeWS Level 1
                                        Andy,
                                        Thanks for the replies. There is no JAVA; this is all standard stuff. Flex 2.01 and ColdFusion 7. Its the Action Script I dont know that well. I really cant do it without a sample of how to loop over the array Collection. I dont know what the code would look like.

                                        Thanks
                                        George
                                        • 18. Re: Datagrid in a form
                                          AndyWW Level 1
                                          Well, I am out of my depth on this one, and I'm sorry that I have wasted your time! I know how frustrating this can be, having posted questions that have gone completely unanswered in these forums.

                                          My suggestion for the grid is that you look at the CF configuration (possibly in your ".cfc" file?) for updating from an array. From a quick look at one of the examples from Adobe it looks as though there is something to do with a cffunction element in the cfc XML, with a returnType of "array" and cfargument element with a type of "array". I have never looked at CF, though!

                                          The example that I looked at is at the URL:

                                          http://www.adobe.com/devnet/flex/articles/coldfusionflex_part2.html

                                          The employees appear to be in an array.

                                          Good luck!

                                          Andy