title: AdvancedDataGrid dataField - how to use a subarray or object in flex?
body: <p>I have an advanced data grid in flex (flash builder 4).  It's dataProvider is pointing to an ArrayCollection (this._encounters).   </p>
  
  <p>Inside that array collection is a property that is an object (a client object).</p>
  
  <p>I tried setting the dataField to "clientObj.firstName" to refer to the first name property within the clientObj property of the this._encounters array collection.  It did not show anything.  </p>
  
  <p>So, I added a labelFunction to that column (code below) to set the text in the cell.  This works fine and now I have values showing in the grid.</p>
  
  <p>The problem is now when I click the title of column to sort it.  It throws an error that property clientObj.firstName is not found in my array collection!</p>
  
  <p>So, is there a better way to set the dataField / source for a column and point at a property in a sub-object -- or a way to fix the sort?</p>
  
  <p>Below the first column</p>
  
  <pre><code>&lt;mx:AdvancedDataGrid x="0" y="25" id="adgEncounters" designViewDataType="flat" width="100%" height="100%" dataProvider="{this._encounters}"&gt;
  &lt;mx:columns&gt;
  &lt;mx:AdvancedDataGridColumn headerText="first" dataField="clientObj.firstName" labelFunction="encounterGridLabelFunct"/&gt;
  &lt;mx:AdvancedDataGridColumn headerText="first" dataField="thisWorksField"/&gt;
  &lt;/mx:columns&gt;
  &lt;/mx:AdvancedDataGrid&gt;
  
  
  
  protected function encounterGridLabelFunct(item:Object, column:AdvancedDataGridColumn):String //put just the HH:MM in to the grid, not the whole date string
  {
   if(column.headerText=="first") result=item.clientObj.firstName;    
   return result;
  }           
  </code></pre>
  
  <p>update:
   Here is the final working code I used.   3 example sort functions, 1 for numeric sorting, 1 for String sorting and one for Date sorting (string date from a database).:</p>
  
  <pre><code>// sort adg column numerically
              private function numericSortByField(subObjectName:String, fieldName:String):Function
              {
                  return function(obj1:Object, obj2:Object):int
                  {
                      var value1:Number = (obj1[subObjectName][fieldName] == '' || obj1[subObjectName][fieldName] == null) ? null : new Number(obj1[subObjectName][fieldName]);
  
                      var value2:Number = (obj2[subObjectName][fieldName] == '' || obj2[subObjectName][fieldName] == null) ? null : new Number(obj2[subObjectName][fieldName]);
                      return ObjectUtil.numericCompare(value1, value2);
                  }
              }
  
              //sort adg column string
              private function stringSortByField(subObjectName:String, fieldName:String):Function
              {
                  return function(obj1:Object, obj2:Object):int
                  {
                      var value1:String = (obj1[subObjectName][fieldName] == '' || obj1[subObjectName][fieldName] == null) ? null : new String(obj1[subObjectName][fieldName]);
  
                      var value2:String = (obj2[subObjectName][fieldName] == '' || obj2[subObjectName][fieldName] == null) ? null : new String(obj2[subObjectName][fieldName]);
                      return ObjectUtil.stringCompare(value1, value2);
                  }
              }
  
              //sort adg date diff (takes date strings for example from a db)
              private function dateSortByField(subObjectName:String, fieldName:String):Function
              {
                  return function(obj1:Object, obj2:Object):int
                  {
                      var value1:String = (obj1[subObjectName][fieldName] == '' || obj1[subObjectName][fieldName] == null) ? null : new String(obj1[subObjectName][fieldName]);
  
                      var value2:String = (obj2[subObjectName][fieldName] == '' || obj2[subObjectName][fieldName] == null) ? null : new String(obj2[subObjectName][fieldName]);
  
                      var value1Date:Date = new Date();
                      var value1Time:int = value1Date.setTime(Date.parse(value1));
  
                      var value2Date:Date = new Date();
                      var value2Time:int = value2Date.setTime(Date.parse(value2));
  
  
                      return ObjectUtil.numericCompare(value1Time, value2Time);
                  }
              }
  </code></pre>
  
  <p>In the mxml above, this is the changed line - notice the stringSortByField added:</p>
  
  <pre><code>        &lt;mx:AdvancedDataGridColumn headerText="first" dataField="clientObj.firstName" sortCompareFunction="{stringSortByField('clientObj','firstName')}" labelFunction="encounterGridLabelFunct"/&gt;
  </code></pre>
  
  <p>If it were a numeric field use the numericSortByField.  If it were a date string from a database, use the dateSortByField function instead.</p>