Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't think the problem is to do with sorting grouped data with null or empty string values (which are perfectly valid values); the docs clearly state the property represented by <code>dataField</code> must be a valid property on the dataProvider [item] i.e. it must exist, null or otherwise.</p> <p>While I give RaySir my vote, I don't quite agree that it's a hack, but rather you're normalizing your data, which I think is a perfectly fine presentation-layer thing to do.</p> <p>Here's is a re-worked example:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" &gt; &lt;mx:Script&gt; &lt;![CDATA[ import mx.collections.HierarchicalData; import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn; import mx.utils.ObjectUtil; private var arrData : Array = [ { name: "User A", dob: "04/14/1980" }, { name: "User B", dob: "01/02/1975" }, { name: "Group A", dob: null, children: [ { name: "User E", dob: "09/13/1972" }, { name: "User F", dob: "11/22/1993" } ] }, { name: "Group B", dob: null, children: [ { name: "Group B1", dob: null, children: [ { name: "User I", dob: "01/23/1984" }, { name: "User J", dob: "11/10/1948" } ] }, { name: "User G", dob: "04/09/1989" }, { name: "User H", dob: "06/20/1963" } ] }, { name: "User C", dob: "12/30/1977" }, { name: "User D", dob: "10/27/1968" } ]; private function dob_sort(itemA:Object, itemB:Object):int { var dateA:Date = itemA.dob ? new Date(itemA.dob) : null; var dateB:Date = itemB.dob ? new Date(itemB.dob) : null; return ObjectUtil.dateCompare(dateA, dateB); } private function dob_dataTip(item:Object):String { if (!item.hasOwnProperty('children') &amp;&amp; item.hasOwnProperty("dob")) { return dateFormatter.format(item.dob); } return null; } private function dob_label(item:Object, col:AdvancedDataGridColumn):String { if(!item.hasOwnProperty('children') &amp;&amp; item.hasOwnProperty("dob")) { return item.dob; } return null; } ]]&gt; &lt;/mx:Script&gt; &lt;mx:DateFormatter id="dateFormatter" formatString="MMMM D, YYYY" /&gt; &lt;mx:AdvancedDataGrid id="adgTest" dataProvider="{new HierarchicalData(arrData)}" designViewDataType="tree" width="746" height="400"&gt; &lt;mx:columns&gt; &lt;mx:AdvancedDataGridColumn headerText="Name" dataField="name"/&gt; &lt;mx:AdvancedDataGridColumn headerText="Date of birth" dataField="dob" labelFunction="dob_label" dataTipFunction="dob_dataTip" sortCompareFunction="dob_sort" showDataTips="true" /&gt; &lt;/mx:columns&gt; &lt;/mx:AdvancedDataGrid&gt; &lt;/mx:Application&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload