1 Reply Latest reply on May 18, 2010 4:18 PM by Flex harUI

    Setting datagrid cell datafields

    sensomage5 Level 1

      Im new to flex and i'm trying to figure this thing out.  I have a script that will take the data from an xml and create new columns for each piece i need.  ie technician names.  So a column for John, a column for Christina, and a column for Louis.  But i need to figure out how to have each of the cells in those columns show information in that column only not accross the whole row. So for exampe.  Column 1 is Joe, i want to show information that only pertains to him so this is what my xml file looks like

      <employees>
                  <employee>
                      <name>John Edwards</name>
                      <status>Assigned</status>
                      <cust>Jacob cook</cust>               
                  </employee>
                  <employee>
                      <name>Louis Freligh</name>
                      <cust>George Bush</cust>
                      <status>Dispatched</status>
                  </employee>
                  <employee>
                      <name>Christina Coenraets</name>
                  </employee>
                  <employee>  

      </employees

       

      So under john if i want to show the customer i would want it to show only johns customer under john only and Louis customer only under louis and if Christina doesnt have a customer then the cell should be blank.  or if it looked like this

      <employees>
                   <employee>
                       <name>John Edwards</name>
                       <status>Assigned</status>
                       <cust>Jacob cook</cust>

                      <cust>James</cust>              

                  </employee>
                   <employee>
                       <name>Louis Freligh</name>
                       <cust>George Bush</cust>

                      <cust>Gary cook</cust>              

                      <cust>jeffery cook</cust>               
                       <status>Dispatched</status>
                   </employee>
                   <employee>
                       <name>Christina Coenraets</name>
                   </employee>
                   <employee>  

      </employees

      I would want it to show johns two customers under him, louis three customers under him and nothing under christina.

       

      I have tried everything i can think of but so far it just auto generates each customer across the whole grid row.

       

      here is the code i wrote to create each column.

       

      private function generateCols(input:XMLList, useAttributes:Boolean = false):Array
              {
                  var e1:XML = input[0];
                  var columns:Array = [];
                  var children:XMLList ;
                  children = e1.children();
                 
                 
                  var child:XML ;
                  for each(child in children)
                  {

       

                      var col:DataGridColumn = new DataGridColumn();

                      var CCust:String = dataListTechnician.employee.cust;
                      var CStatus:String = dataListTechnician.employee.status;
      //                if (CCust == "") {
      //                    col.dataField = ""
      //                } else {

       

      //                }
                        col.dataField = "cust"
                      var fieldName:String = dataListTechnician.employee[currIdx].name;
                      col.headerText = fieldName
                      columns.push(col)
                  }
                  return columns;


              }

       

      I've looked online for about 4 hours and havent found anything that would help me so any help would be appreciated!

       

      Thanks

        • 1. Re: Setting datagrid cell datafields
          Flex harUI Adobe Employee

          DataGrid cannot do that for that data set.  Each row must contain the same

          fields.  One row cannot be name and another row cannot be status.

           

          There might be some pivot table components you can use, or you can modify

          the data set or try rotating the DataGrid.

           

          There is also a DataGrid prototype based on Spark List on my blog that you

          might be able to modify to do this

           

          --

          Alex Harui

          Flex SDK Team

          Adobe System, Inc.

          http://blogs.adobe.com/aharui