9 Replies Latest reply on Jan 25, 2007 3:59 PM by Hugo_Core

    how to read datagrid rows

    vijjubabu
      hi all
      i want to take the data from datagrid row by row
      how can i do that

      plz help me
        • 1. Re: how to read datagrid rows
          peterent Level 2
          You don't take the data from the DataGrid, you use its dataProvider. For example:

          [Bnidable] private var dp:ArrayCollection = new ArrayCollection(
          [ {product:"Apples", quantity:23000, price:0.45}, {product:"Oranges", quantity:50039, price:0.69}, ... ]);

          <mx:DataGrid id="myGrid" dataProvider="{dp}" ...>
          ...
          </mx:DataGrid>

          You can either loop though the dp ArrayCollection or myGrid.dataProvider - they are the same thing. If you DataGrid is editable, your dataProvider collection will be modified with the edits.
          • 2. Re: how to read datagrid rows
            vijjubabu Level 1
            thank u peterent
            but my datagrid is editable
            im populating datagrid with arraylist in editable mode only
            then im editing the datagrid then i hav to save the edited data
            while saving the data i hav to take the edited data from the datagrid

            is it work with code what u sent??????/
            just reply me!!!!!!!!!!!!


            plz reply ASAP

            thanx
            vijaykotha
            • 3. Re: how to read datagrid rows
              peterent Level 2
              The DataGrid does not store any data - it uses a dataProvider, usually an ArrayCollection. You can access that collection using the DataGrid's id and the dataProvider property:

              var numItems:Number = (mygrid.dataProvider as ArrayCollection).length;

              Even though your entire grid is editable, the values are being stored in the DataGrid's dataProvider.
              • 4. how to read datagrid rows
                Hugo_Core Level 1
                Hellloooooo vijjubabu and peterent...

                vijjubabu , i have a older topic that peterent hint me with something familiar.

                http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=585&threadid=1232180

                My goal, still is, because the topic wasn't resolve it, save the edited cells or rows just like you, to my MySQL db. I will use PHP has a intermidier. That's not important. Important its to retrieve the data.

                I'm using a HTTPService to retreavie , and after peterent explanations i realise that i would use another HTTPService to save the records from the DataGrid.

                On my several days of research i created the HTTPServices, and a simple function that will loop thought the DataGrid.
                <mx:Script>
                <![CDATA[
                import mx.controls.Alert;

                import mx.collections.ArrayCollection;
                import mx.rpc.events.ResultEvent;

                [Bindable]
                private var myData:ArrayCollection;

                private function resultHandler(event:ResultEvent):void {
                myData = event.result.db.data;
                }


                private function loop():void {

                var i:Number = 0; // Beginning
                var f:Number = myData.length; // Final Index


                for (i=0; i<f; i++) { // the looping thing..
                block.text += "<data><id>" + myData .id + "</id><titulo>" + myData.titulo + "</titulo></data>" + "\n";
                trace(myData );
                }

                }


                ]]>
                </mx:Script>

                I have setup a TextArea ( id=Block) just to see what's going on with the code.

                Questions:
                -If we create a cloned ArrayCollection, in a way that we will have a Original and Edited ArrayCollections, how can we compare the two and save the results? Maybe with a FilterFunction ?

                -We for send the results by the HTTPService, it would be like this right ? :
                service.send({value:updateInfo})

                I Hope that someone continue helping.
                Core Regards...
                • 5. Re: how to read datagrid rows
                  vijjubabu Level 1
                  hi peterent and huge_core

                  my requirement is like this

                  in flex page i have edited datagrid with some arraycollection
                  then on clicking of save button i have to store it in database

                  for that im using struts framework forget about struts (i ll take care)

                  just suggest me in this regard

                  when clicking save button i am taking edited datagrid collection
                  then i have to add this array collection to Httpserive request

                  how can i add arraycollection to httpservice request
                  syntax and all i need..

                  if v add arraycollection to the request then i can take it in action class and doing the appropriate operations
                  so my qn is how v can add arraycollection to the httpservice request

                  thanx in advance

                  help me plz..............
                  • 6. how to read datagrid rows
                    Hugo_Core Level 1
                    Core here..

                    vijjubabu we are on the same step :P

                    My way, to do what you and i want is, loop throw the dataGrid and create a XML with the changed rows and send it by the HTTPService.

                    im still worinking on it. WIP

                    I Already have the loop function, the one i post'it..

                    To Do is : The Function to compare the before and the edited Array's and create a new one with the matches, and for last, send it by the HTTPService.

                    i will keep posting my codes, try to play a little you too.

                    Yesterday i saw an little code from peterent that respond to my question:

                    -If we create a cloned ArrayCollection, in a way that we will have a Original and Edited ArrayCollections, how can we compare the two and save the results? Maybe with a FilterFunction ?

                    by peterent:
                    var matches:ArrayCollection = new ArrayCollection();
                    for(var c:int=0; c < catCollection.length; c++) {
                    if( catCollection[c].catID == catSelected ) matches.addItem( catCollection[c] );
                    }


                    I will work on this , if you get something post it ;)

                    Core..out..
                    • 7. Re: how to read datagrid rows
                      peterent Level 2
                      What you can send to the server depends on which Flex data service you use and what the server code is expecting. With HTTPService you have some limitations. For example, if you use method="GET" then you can only provide what a normal URL allows (and its character limit) since you are essentially sending parameter=value&paramter=value&etc. in the URL.

                      Using HTTPService with method="POST" allows you to send more data. This would be useful if your server-side program could accept XML. Then you could loop through your dataProvider collection and build an XML string and send it using HTTPService with method="POST".

                      Using WebService gives you more flexability, but you need a SOAP-based web service to receive the information.

                      Using RemoteObject gives you the most power and ease of use, but your server needs to be something that understands the AMF protocol, such as ColdFusion 7.0.2 or Flex Data Services.
                      • 8. how to read datagrid rows
                        Hugo_Core Level 1
                        quote:

                        Using HTTPService with method="POST" allows you to send more data. This would be useful if your server-side program could accept XML. Then you could loop through your dataProvider collection and build an XML string and send it using HTTPService with method="POST".


                        That is my goal, and i have been working. Loop the dataProvider collection , create an XML and send'it..But only with the changed values, if possible :P..

                        Here the Code Steps for understand for good this subject:

                        Retrieve from Server

                        Build the ArrayCollection (myData)]

                        Clone the last and work on this collection (myCloned)

                        After the user modify throw a dataGrid the myCloned collection, compare the two collections for differences

                        The results will go to a third collection(toServer)

                        Send this last by a HTTPService in POST mode on a XML


                        What your opinion..?







                        I'm on the clone step.. How can we clone/replic a ArrayCollection so can be used by our dataGrid?

                        i try this but with no sucess, the dataGrid stills use the myOriginal Collection

                        var myCloned:ArrayCollection = new ArrayCollection();
                        for(var c:int=0; c < myData.length; c++) {
                        myCloned.addItem(myData[c]);
                        }



                        core .. wip..
                        • 9. how to read datagrid rows
                          Hugo_Core Level 1

                          1.Retrieve from Server
                          2.Build the ArrayCollection (myData)]
                          3.Clone the last and work on this collection (myCloned)

                          Done

                          4.Into the compare process >>>

                          vijjubabu are you following me.. ?