5 Replies Latest reply on Jan 19, 2007 4:56 PM by Hugo_Core

    Save DataGrid

    Hugo_Core Level 1
      Hi every flex addicted:P

      Does anybody knows a way to save the changes realized to a dataGrid?

      DataGrid have editable="true" , the goal is to save to a MySql, but all ideias are welcome to find a way...

      My ideias are, use a PHP script to receve the data..but how?
        • 1. Re: Save DataGrid
          Hugo_Core Level 1
          anyone ?
          • 2. Re: Save DataGrid
            peterent Level 2
            The Flex UI application - which is really a Flash Movie (SWF) running in the Flash Player on the client machine - cannot save data to a database. You have to transfer the data to a server which has the capability to do that.

            You have a number of choices:

            Use HTTPService and send the data to a PHP script, a JSP, an ASP. Make sure the response from that request returns something that HTTPService can digest, such as a simple text string (eg, "OK"), a name=value pair (eg, result=OK), an XML document (eg, <response><status>OK</status></response>) etc. I vote for XML because you can be very flexible with your response. For example, if you save a record to the database and the database assigns an ID, you could return that ID or you could return an error message.

            Use WebService and send the data to some web service which might be Java, C#, ColdFusion, etc.

            Use RemoteObject and ColdFusion 7.0.2 Flex Connectivity Kit. This allows you to send 'objects' between the Flex app(SWF) and a ColdFusion Component (CFC). For example, suppose the data you have in ActionScript are instances of an ActionScript class (eg, class Person). You can write a corresponding person.cfc and, using RemoteObject, invoke a CFC in ColdFusion and pass the ActionScript class objects right over to CF which will becomes person.cfc instances and then can be saved to the database using CF technology. Its quite easy to do.

            Use Flex Data Services. FDS is another product in the Flex family. FDS makes it easy to work with databases such as Hibernate. We have examples of doing this on our Flex web site and there are examples that come with FDS. You might download the FDS trial and check it out.

            It really depends on the complexity of the data and overall project. An enterprise-level application should probably go with FDS; HTTPService might be more suitable to a mom-and-pop application. A e-commerce site would do well with ColdFusion.

            All of our products, if not free, have trial downloads you can use to check things out.
            • 3. Re: Save DataGrid
              Hugo_Core Level 1
              Hello peterent , how you doing ?

              Thank you very much for the explanation that really helps.

              For my type of solution i think HTTPService is the right way to do it. My application it´s very easy, it's just a WebSite Adminstrator to manager products and categories.

              Chossing HTTPService, peterent, how can i (using the AS3) send the fields that have been change (or all) in the DataGrid, noting that she is EDITABLE on Click

              Waiting for feedback,
              Hugo Core []
              • 4. Re: Save DataGrid
                peterent Level 2
                Flex doesn't have a way to say 'this data has changed', you'll need to develop some system for keeping track of which fields in which records have changed. You can decide to send all of the data, just the records that have changed, or the specific record/field that have changed. You decide.

                One common technique is to exchange data in XML. For example, when your program starts you might request all of the data from the server. The server would respond with an XML document.

                When you want to update the data, you would send a smaller XML document containing just the information changed.

                <mx:HTTPService id="updateData" url=" http://yourdomain.com/yourserver" method="POST" ... />

                Then in ActionScript, you can do:

                var updateInfo:XML = <update><field name="firstName" value="something"> ... </update>;

                You would have to programmatically build the response XML; I just hard-coded an example. The send() function of HTTPService can be given an object whose properties correspond to request parameters the server code is expecting.
                • 5. Save DataGrid
                  Hugo_Core Level 1
                  I have it all configurated beside the part that retrieves the data from the DataGrid,

                  How can we call all the data from DataGrid and send by HTTPService

                  Im just cant find a sample with that, if sameone have the caind of post something i apreciated..