Saturday, October 11, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Jan 2008 >>
S M T W T F S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search

Categories
 • Acrobat (2) [RSS]
 • Adobe (68) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (25) [RSS]
 • AIR (134) [RSS]
 • Appearances (122) [RSS]
 • Books (69) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1154) [RSS]
 • Data Services (13) [RSS]
 • Fish Tank (2) [RSS]
 • Flash (106) [RSS]
 • Flex (372) [RSS]
 • Home Automation (3) [RSS]
 • Jobs (96) [RSS]
 • JRun (13) [RSS]
 • Labs (27) [RSS]
 • LiveCycle (22) [RSS]
 • MAX (160) [RSS]
 • Regular Expressions (13) [RSS]
 • RIA (11) [RSS]
 • SQL (38) [RSS]
 • Stuff (505) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (137) [RSS]
 • Wireless (99) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Day : January 21, 2008 / Main
January 21, 2008

InsideRIA Now Online

InsideRIA.com is an online community dedicated to all things RIA. InsideRIA.com is developed by O'Reilly and sponsored by Adobe Systems Incorporated.


Heading Down To Orlando

I am on my way down to Orlando for tonight's Flex / AIR Pre-Release Tour presentation to the Adobe Developers of Greater Orlando group. The full tour location list is online.


Grouping Data With Flex 3 AdvancedDataGrid

The enhancements to the data grids in Flex 3 have been eagerly anticipated, and are greatly appreciated - especially by us ColdFusion developers who spend so much time creating highly data-centric applications. I plan on providing examples of how to use the new data grids with ColdFusion, and here is the first.

AdvancedDataGrid supports group expanding and collapsing within grids, think of it as a grid with an embedded tree control. Multiple levels of grouping are supported (each level becomes a tree branch), but this example uses a single level for simplicity's sake.

The example uses the default database tables that come with ColdFusion 8, and here is the simple CFC method which just returns several columns from two tables:

<cfcomponent>

   <cffunction name="getArtByMedia" access="remote" returntype="query">
      <cfset var result="">

      <cfquery datasource="cfartgallery" name="result">
      SELECT mediatype, artname, description, price
      FROM media, art
      WHERE media.mediaid=art.mediaid
      ORDER BY mediatype, artname
      </cfquery>

      <cfreturn result>
   </cffunction>

</cfcomponent>

I saved this component as art.cfc in a folder named test beneath the web root. You can save it wherever you like, but of course you'll need to adjust the path in the MXML accordingly. Here is the MXML:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
         layout="vertical" width="100%" height="100%"
         creationComplete="initApp()">


   <mx:Script>
      <![CDATA[
         // Init
         public function initApp():void
         {
            // Get data
            svc.getArtByMedia();
         }
      ]]>
   </mx:Script>


   <!-- Define CFC -->
   <mx:RemoteObject id="svc"
            destination="ColdFusion" source="test.Art"
            result="gc.refresh()" />


   <!-- The grid -->
   <mx:AdvancedDataGrid width="100%" height="100%">

      <!-- Define grouping in dataProvider -->
      <mx:dataProvider>
         <mx:GroupingCollection id="gc" source="{svc.getArtByMedia.lastResult}">
            <mx:Grouping>
               <mx:GroupingField name="MEDIATYPE" />
            </mx:Grouping>
         </mx:GroupingCollection>
      </mx:dataProvider>

      <!-- The grid columns -->
      <mx:columns>
         <mx:AdvancedDataGridColumn dataField="MEDIATYPE"
            headerText="Media"/>

         <mx:AdvancedDataGridColumn dataField="ARTNAME"
            headerText="Name" />

         <mx:AdvancedDataGridColumn dataField="DESCRIPTION"
            headerText="Description" />

         <mx:AdvancedDataGridColumn dataField="PRICE"
            headerText="Price" textAlign="right" />

      </mx:columns>

   </mx:AdvancedDataGrid>

</mx:Application>

<mx:RemoteObject> points to the CFC. <mx:AdvancedDataGrid> defines the grid and columns, in much the same way as regular <mx:DataGrid> does. But unlike <mx:DataGrid>, here the dataProvider is passed as a child tag so as to be able to specify additional information. <mx:AdvancedDataGrid> can accept hierarchical data ready to be used for grouping, as well as flat data, in which case a GroupingCollection must be used so that Flex can regroup the data hierarchically. As ColdFusion queries are flat (non-hierarchical), a GroupingCollection is defined using <mx:GroupingCollection>. The GroupingCollection accepts one or more fields to be grouped on, and here a single field is specified using <mx:GroupingField>.

When using GroupingCollections like this, the data grid itself must explicitly be refreshed so that the changes are reflected in the displayed grid. According to the documentation, this example would do this as <mx:AdvancedDataGrid ... initialize="gc.refresh()">, but this does not seem to work. Instead, the refresh() method is specified in <mx:RemoteObject> so that it is called when data is received. (Thanks to Mike Nimer for figuring this one out for me!).

And there you have it, a really simple data grid with expand/collapse grouping.

  © Copyright 1997-2008 Ben Forta, All Rights Reserved