5 Replies Latest reply on Oct 6, 2010 10:38 PM by kglad

    Datagrid to String

    Neat Gadget Level 1
      Hi,

       

      I want to convert a datagrid back to a string. I tried

       

      Code:
      var myString = _root.myDatagrid.toString();
      But this does not seem to work.
        • 1. Re: Datagrid to String
          kglad Adobe Community Professional & MVP

          the datagrid is complex component.  there's nothing that you could convert to a string.

           

          are you talking about the datagrid's dataProvider property (which is an array of objects)?

          • 2. Re: Datagrid to String
            Neat Gadget Level 1

            Well I supose all I want is the data that the datagrid uses, which is the dataprovider.

            • 3. Re: Datagrid to String
              kglad Adobe Community Professional & MVP

              ok, that's doable.  but how you do it depends on what you're going to do with the string.

               

              are you saving it to a text file so you can later read that text file and reconstruct the dataProvider?

              • 4. Re: Datagrid to String
                Neat Gadget Level 1

                Thanks for your reply. Essentially all I need to do is export it as a CSV file. There is no need to read it back in.

                 

                Just to add that I am using Zinc MDM so I have the ability to save to file in the following way:

                 

                var myFolder:String = mdm.Dialogs.BrowseFolder.show();
                mdm.FileSystem.saveFile(myFolder + fileName, myCSVFile);

                • 5. Re: Datagrid to String
                  kglad Adobe Community Professional & MVP

                  i think you'll probably want something more than a csv list but if that's what you think you want you can use:

                   

                  var s:String = "";

                  for(var i:Number=0;i<yourDG.dataProvider.length;i++){

                  for(var objS:String in yourDG.dataProvider[i]){

                  s += objS+","+yourDG.dataProvider[i][objS]+",";

                  }

                  }

                  s = s.substr(0,s.length-1);

                   

                  but it will be easier to reconstruct your dp is you use something like:

                   

                  var s:String = "";

                  for(var i:Number=0;i<yourDG.dataProvider.length;i++){

                  for(var objS:String in yourDG.dataProvider[i]){

                  s += objS+":"+yourDG.dataProvider[i][objS]+",";

                  }

                  s = s+",";

                  }

                  s = s.substr(0,s.length-2);

                   

                  that way each dp element is seperated by a double comma (,,) , the objects are seperated by commas (,) and each object consists of a property and value seperated by a colon (:).