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

    AdvancedDataGrid with XMLListCollection Syntax

    Travo81
      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">
      <java:AssociatedFileID>9999</java:AssociatedFileID>
      <java:AssociatedFileName>example.csv</java:AssociatedFileName>
      <java:DataBucketID>123</java:DataBucketID>
      <java:DataBucketName>EDashboard</java:DataBucketName>
      <java:Fields>
      <java:DataBucketFieldName>Business</java:DataBucketFieldName>
      <java:DataBucketFieldValue>Loans</java:DataBucketFieldValue>
      <java:DataBucketFieldID>4281</java:DataBucketFieldID>
      </java:Fields>
      <java:Fields>
      <java:DataBucketFieldName>Section</java:DataBucketFieldName>
      <java:DataBucketFieldValue>Europe</java:DataBucketFieldValue>
      <java:DataBucketFieldID>4394</java:DataBucketFieldID>
      </java:Fields>
      <java:LoadedDateTime>2008-03-19T10:57:21-04:00</java:LoadedDateTime>
      <java:Suppressed>No</java:Suppressed>
      <java:DataBucketContentID>170</java:DataBucketContentID>
      <java:Status>Active</java:Status>
      </java:Results>

      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:columns>
      <mx:AdvancedDataGridColumn headerText="ID" dataField=""/>
      <mx:AdvancedDataGridColumn headerText="Business" dataField=""/>
      <mx:AdvancedDataGridColumn headerText="Section" dataField=""/>
      </mx:columns>
      </mx:AdvancedDataGrid>

      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?

      Thanks,

      Trav
        • 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:
          dataField="java::DataBucketContentId"

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

          Tracy
          • 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.
              Tracy
              • 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>
                <person>
                <FirstName>Santa</FirstName>
                <Surname>Claus</Surname>
                <Age>1000</Age>
                </person>
                <person>
                <FirstName>Tooth</FirstName>
                <Surname>Fairy</Surname>
                <Age>250</Age>
                </person>
                <person>
                <FirstName>Travis</FirstName>
                <Surname>Allen</Surname>
                <Age>27</Age>
                </person>
                </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:columns>
                <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-->
                </mx:columns>
                </mx:DataGrid>
                Hope this helps anyone else!

                Trav