[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 566
  • Last Modified:

Convert Flex Datagrid results into a string

Hey,

I've spent WAYY too many hours trying to figure this out, and about to pull my hair out. I have a Flex Datagrid that I'm trying to convert into a SIMPLE string. My function is the following:

A couple problems:

Problem #1 - When the datagrid converts to a string, the order of the items in my string are arranged in an adhoc manner. So for example if the first row of the datagrid contains the <First Name> , followed by the <Last Name>, followed by the <Age>, the iteration over obj2 doesn't stay in the <First Name> <Last Name> <Age> order...the order always spits out randomly! What is really interesting is that on different computers, the order changes, but on the same computer, the order doesn't change. Is there a better way to save the datagrid results to a string?

The second problem - When you iterate over obj2, there is this wierd binary string that comes out like 078285D5-7022-17BC-4EE3-98E93E8696A4

What sucks is that now that "078285D5-7022-17BC-4EE3-98E93E8696A4" is also added into my string. You'll notice that I've tried taking it out in my code but, it doesn't work all the time.



private var file:FileReference = new FileReference();
private var myString:String = new String
private var sTemp:String = new String
private var inti:Number
private var intCountDash:Number
			
private function ExporttoCSV():void{
myString = "Cost, Attribute, Change, PV, Level, ROI\r\n"
for each( var obj:Object in myData )
{
for each( var obj2:Object in obj )
{
intCountDash = 0;
var encr_int: Number=0;
trace(String(obj2));
for (inti=0; inti < String( obj2 ).length; inti++) 
{	
if(String( obj2 ).charAt(inti) == '-') 
	{
         						intCountDash = intCountDash + 1;
         					}
      					}
	  					if (sTemp != "")
	  					{		
							if (intCountDash !=4)
							{
								if (String( obj2 ) == "&#8593;")
								{
									sTemp += "," + "Increased from Current";
								}
								if (String( obj2 ) == "&#8595;")
								{
									sTemp += "," + "Decreased from Current";
								}
								if (String( obj2 ) == "&#8596;")
								{
									sTemp += "," + "No Change";
								}
								if ((String( obj2 ) != "&#8593;") && (String( obj2 ) != "&#8595;") && (String( obj2 ) != "&#8596;"))
								{
									sTemp += "," + String( obj2 )	
								}
							}
						}
						else
						{
							sTemp = String( obj2 )
						}
					}
					myString += sTemp + "\r\n";
					trace(myString);
					sTemp = "";
				}
				

                        //var test:String = "Hello World, By World"
                        file.save(myString,'Report.txt');
            }

Open in new window

0
piyushdabomb
Asked:
piyushdabomb
1 Solution
 
CarnouCommented:
I see that you start your string by defining what the output will be, so you presumably know the exact columns in your data grid.  In that case, why go generic?
I would try something like this, starting at line 8:
myString = "Cost, Attribute, Change, PV, Level, ROI\r\n";
var costCol:DataGridColumn =  myData.columns[0];
var attrCol:DataGridColumn = myData.columns[1];
var changeCol:DataGridColumn = myData.columns[2];
var pvCol:DataGridColumn = myData.columns[3];
var levelCol:DataGridColumn = myData.columns[4];
var roiCol:DataGridColumn = myData.columns[5];

for (var i:int = 0; i < myData.rowCount; ++i)
{
    row:Object = myData.getItemAt( i );
    myString += costCol.itemToLabel( row ) + ", ";
    myString += attrCol.itemToLabel( row ) + ", ";
    myString += changeCol.itemToLabel( row ) + ", ";
    myString += pvCol.itemToLabel( row ) + ", ";
    myString += levelCol.itemToLabel( row ) + ", ";
    myString += roiCol.itemToLabel( row ) + "\r\n";
}
file.save(myString,'Report.txt');
I haven't tested this code in any way, but it looks like it should work.
reference: http://www.wuup.co.uk/as3-quick-tips-datagrid-how-to-extract-data-from-a-single-cell-in-a-datagrid-component/ for how to get any individual value from a cell.
Good luck!
0
 
piyushdabombAuthor Commented:
I haven't tested this out, but I figured out how to go around it. Thanks a lot!

If I ever need this, I will use it. I was simply in a rush to finish my project.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now