4 Replies Latest reply on Mar 31, 2008 6:55 PM by Travo81

    AdvancedDataGrid with XMLListCollection Syntax

      Hello All,

      I'm more of an XSLT/XPath guy, and need help with the syntax for Flex(if that's the only thing I'm doing wrong!). I have an XMLListCollection named "mapData" with records from a web service. Each record looks like this:

      <java:Results xmlns:java="java:com.example.com">

      My AdvancedDataGrid is:

      <mx:AdvancedDataGrid x="10" y="10" id="MapDG" designViewDataType="flat" width="100%" height="100%" dataProvider="{mapData}" click="{editBtn.enabled=true;}" selectionMode="singleRow" change="{editBtn.enabled=true;}">
      <mx:AdvancedDataGridColumn headerText="ID" dataField=""/>
      <mx:AdvancedDataGridColumn headerText="Business" dataField=""/>
      <mx:AdvancedDataGridColumn headerText="Section" dataField=""/>

      Here's what I'm trying to do for each column:

      1 - *::Results.*::DataBucketContentID.text()
      //this is the record ID
      2. - *Results.*::Fields.(*::DataBucketFieldName.text()='Business').*DataBucketFieldValue.text( )
      //Gets the 'DataBucketFieldValue' for each 'Fields' that has a 'DataBucketFieldName' = Business
      3. - *Results.*::Fields.(*::DataBucketFieldName.text()='Section').*DataBucketFieldValue.text()
      //Gets the 'DataBucketFieldValue' for each 'Fields' that has a 'DataBucketFieldName' = Section

      What do I need to put in the columns' dataField for this to work?


        • 1. Re: AdvancedDataGrid with XMLListCollection Syntax
          ntsiii Level 3
          Looks like you will need to include the namespace in all expressions. Or, you can set the namespace using the Namespace manager. Yo will need to read up / search for more info on this, I have been able to avoid namespaces so far.

          Next, if the value you want is a top-level property (first level child node) of each item, you can set the dataField directly. Maybe:

          If the values you want are more deeply nested as appear the values under "Fields", you will need to use a labelFunction.

          • 2. Re: AdvancedDataGrid with XMLListCollection Syntax
            Travo81 Level 1
            Thanks Tracey! It's nested so I guess I have to labelFunction. It's new to me, but I'll research it and see what happens.
            • 3. Re: AdvancedDataGrid with XMLListCollection Syntax
              ntsiii Level 3
              I have a simple example of using a labelFuncrion with nested xml on www.cflex.net. Search there for labelFunction.
              • 4. Re: AdvancedDataGrid with XMLListCollection Syntax
                Travo81 Level 1
                Thanks to Tracy and a little research, I have my data grid populating - I wanted to post an example that worked for me:
                If below is a variable with your web service result...

                private var personXML:XML=<persons>

                You can use a function, which you'll need to assign to a column. Here it is concating text in 2 elements but you can also use it for namespaced elements (e.g. item.*::NodeName1.*::NodeName2.text()).

                private function showFullName(item:Object, Column:DataGridColumn):String{
                var fullName:String = item.FirstName + " " + item.Surname;
                return fullName;

                The first column uses the function to populate the data in the column. It has to use labelFunction (vs. dataField). The 2nd uses the node name directly.

                <mx:DataGrid id="personDG" dataprovider="{personXML.person}">
                <mx:DataGridColumn width="150" headerText="Full Name" labelFunction="showFullName"/>
                <mx:DataGridColumn width="150" dataField="Age" width="50"/>
                <!--the column without header text wil take the value of the element-->
                Hope this helps anyone else!