5 Replies Latest reply on Aug 21, 2006 8:40 AM by inlineblue

    data grid component

    sam luke Level 1
      Currently I am trying to create a datagrid component which will contain the data values of an xml file. The xml file has nested elements. For example:

      <employee>
      <name>paul</name>
      <information>
      <home>xxxx</home>
      <phone>1234</phone> .....

      From all the examples I have seen the xml data only has multiple columns of data but this is not nested. Please can somebody help with this?
        • 1. data grid component
          inlineblue Level 1
          For complex situations like that, you'll have to make use of the DataGrid's labelFunction. The function might look something like this:

          private function getLabel(item:Object, column:DataGridColumn): String
          {
          if (column.headerText == "phone")
          return item.information.phone;
          if (column.headerText == "home")
          return item.information.home;
          //etc...
          }

          Look in the docs for more details.
          • 2. Re: data grid component
            sam luke Level 1
            Thanks for the reply. I have followed your example and have found that, in my case:

            1. Each row contains ALL the data for each particular tag/element.
            2. All the data within each row contains NOT only the string but the xml tag. ie <phone>. I have used the .toString() function but this has not changed the display!

            I can see that I can implement action script to achieve what I need using the labelFunction() but there must be an easier approach then this. Does anybody know?
            • 3. Re: data grid component
              inlineblue Level 1
              I'm not clear on what your datagrid or you XML data looks like exactly. Please post an example.
              • 4. Re: data grid component
                sam luke Level 1
                I have included an mxml example below. The problem is getting the datagrid datafield to access the nested tags of say employee.information.home. You can see from the example below that I have tried accessing the nested tag using dataField="information.home. But this doesnt work.

                <?xml version="1.0"?>
                <!-- DataGrid control example. -->
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

                <mx:XMLList id="work">
                <employee>
                <name>paul</name>
                <information>
                <home>xxx</home>
                <phone>123</phone>
                </information>
                </employee>
                <employee>
                <name>clare</name>
                <information>
                <home>xxx</home>
                <phone>123</phone>
                </information>
                </employee>
                </mx:XMLList>

                <mx:Panel title="DataGrid Control Example" height="100%" width="100%"
                paddingTop="10" paddingLeft="10" paddingRight="10">

                <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{work}">
                <mx:columns>
                <mx:DataGridColumn dataField="name" headerText="Name"/>
                <mx:DataGridColumn dataField="information.home" headerText="home"/>
                <mx:DataGridColumn dataField="phone" headerText="phone"/>
                </mx:columns>
                </mx:DataGrid>
                </mx:Panel>
                </mx:Application>
                • 5. Re: data grid component
                  inlineblue Level 1
                  In this case, there is no quick way to solve it. You'll have to use the labelFunction to get at nested data.