You are in luck.  I needed a simple project to work on for FB2, so I
made your example.  Beware though, it is only my second Flex2 app.  My
first was "hello, world".
Tracy

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

<mx:Script><![CDATA[
  import mx.controls.dataGridClasses.DataGridColumn;
      private var gXMLDoc:XML;
      private function initApp():void
      {
            gXMLDoc =
        <users>
            <user>
                <username gender="male">Joe</username>
                <useremail>[EMAIL PROTECTED]</useremail>
                <location id="001">
                     <city>Bedford</city>
                     <state>MA</state>
                </location>
            </user>
            <user>
                <username gender="female">Maggie</username>
                <useremail>[EMAIL PROTECTED]</useremail>
                <location id="002">
                     <city>Lexington</city>
                     <state>MA</state>
                </location>
            </user>
        </users>
    dg1.dataProvider = gXMLDoc.user;
      }//initApp
     
      private function lfnGeneral(item:Object,
column:DataGridColumn):String
      {
        var sLabel:String = ""
        var sHeaderText:String = column.headerText
        switch (sHeaderText)  {
          case "Name":
            sLabel = item.username;
            break;
          case "Email":
            sLabel = item.useremail;
            break;
          case "City":
            sLabel = item.location.city;
            break;
          case "State":
            sLabel = item.location.city;
            break;
          case "Gender":
            sLabel = [EMAIL PROTECTED];
            break;                                               
        }

        return sLabel;
      }//lfGeneral

]]></mx:Script>

      <mx:DataGrid id="dg1">
   <mx:columns>
      <mx:Array>
         <mx:DataGridColumn headerText="Name" labelFunction="lfnGeneral"
/>
         <mx:DataGridColumn headerText="Email"
labelFunction="lfnGeneral" />
         <mx:DataGridColumn headerText="City"
labelFunction="lfnGeneral" />
         <mx:DataGridColumn headerText="State"
labelFunction="lfnGeneral" />
         <mx:DataGridColumn headerText="Gender"
labelFunction="lfnGeneral" />
         </mx:Array>
      </mx:columns>
   </mx:DataGrid>
</mx:Application>

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of josulliv101
Sent: Thursday, May 18, 2006 3:35 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: newbie question: Populating Datagrid from
external complex xml

Thanks - i will try it. i am using Flex 2 beta 3.
-Joe

--- In flexcoders@yahoogroups.com, "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> Have you tried using a labelFunction on each column?
>
> That function gets run for every element in the dataProvider array
and gets passed a reference tothat item.
>
> You can use whatever logic you need to navigate to the data you
need, and then return that for the dataGrids use.
>
> Take a look at this, and if you need more help post back.  I might
be able to do a quick example.
>
> What version of Flex, by the way?
>
> Tracy
>
>
>
> -----Original Message-----
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED]
On Behalf Of josulliv101
> Sent: Thursday, May 18, 2006 12:48 PM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] newbie question: Populating Datagrid from
external complex xml
>
> Hi,
>
> I don't have any issues populating the datagrid when my external xml
> file is very basic. for example:
>
> <users>
>     <user>
>         <username>Joe</username>
>         <useremail>[EMAIL PROTECTED]</useremail>
>     </user>
>     <user>
>         <username>Maggie</username>
>         <useremail>[EMAIL PROTECTED]</useremail>
>     </user>
>
> </users>
>
> But when I have many nested elements and attributes - I can never
> access the elements deeper within the xml.
>
> Can anyone put up a bare-bones example of populating a datagrid with
> something like the following from an xml file.
>
>
> <users>
>     <user>
>         <username gender="male">Joe</username>
>         <useremail>[EMAIL PROTECTED]</useremail>
>         <location id="001">
>              <city>Bedford</city>
>              <state>MA</state>
>         </location>
>     </user>
>     <user>
>         <username gender="female">Maggie</username>
>         <useremail>[EMAIL PROTECTED]</useremail>
>         <location id="002">
>              <city>Lexington</city>
>              <state>MA</state>
>         </location>
>     </user>
>
> </users>
>
> Any help is appreciated.
> Thanks,
> Joe
>
>
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links











--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to