Looping Through Datagrid Rows in Flex

It wasn't readilly apparent to me how to loop through some datagrid rows in Flex. Finally, I came across Abdul Qabiz's DataGridDataExporter class, which basically does just that.

The key is to set up a cursor that will loop through the Data Provider for the datagrid.

Something like this:

ACTIONSCRIPT:
  1. var dp:Object=MyDG.dataProvider;
  2. var cursor:IViewCursor=dp.createCursor();
  3. while( !cursor.afterLast )
  4. {
  5.   // Access each column field like: cursor.current.MyFieldName
  6.   trace(cursor.current.MyFieldName);
  7.   // Obviously don't forget to move to next row:
  8.   cursor.moveNext();
  9. }

That's all there is to it.

Note for Flex Newbie: Test Your HTML Wrapper

Note to self (the Flex newbie): Test your HTML wrapper for your SWF files to make sure that the user experience is a good one when you're setting up your Flex apps on your site! I took the HTML wrapper generated by Flex Builder and modified it to fit into my page. While doing so, I forgot to include the playerProductInstall.swf file with my app, so when a browser with an older Flash Player viewed the page, the JavaScript I had in place to call playerProductInstall.swf would hang since it couldn't find it. The detection for when no Flash Player is present at all (or only a really old version) was also a bit ungraceful.

But I was clueless to these poor experiences since I hadn't tested these scenarios. Fortunately, my app was just released, and only to a beta crowd.

To test the absence of Flash Player, you can download a Flash Player Uninstaller and uninstall Flash Player. I'm not sure what the best way is to install and test an old version of the Flash Player; I just had a virtual machine that had an old version on it, so I used that because it was convenient. If you google for "download flash player 8", there are some non-Adobe links that appear to be valid links, but I did not try these.

Adobe has a Flash Player Detection and Installation support page that is helpful as well.

  Theme Brought to you by Directory Journal and Elegant Directory.