I have an AdvancedDataGrid that uses client data grouping. Not all groups will be at the same level in the hierarchy, and groups can contain both groups and members. We have a sort callback, but it is not called, with the exception of groups on a variety of sheets. See the code below for an example — expand all groups, then click the sort column in the date of birth field to get reverse sorting by date of birth. (Oddly enough, for some incomprehensible reason, the first upstream sorting works.)
We do not call any of the data grouped at the same level as a member of the group.
How to fix it?
Thank.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" >
<mx:Script>
<![CDATA[
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.collections.HierarchicalData;
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", children: [
{ name: "User E", dob: "09/13/1972" },
{ name: "User F", dob: "11/22/1993" }
]
},
{ name: "Group B", children: [
{ name: "Group B1", 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 date_sortCompareFunc(itemA:Object, itemB:Object):int
{
if ( itemA.hasOwnProperty("dob") && itemB.hasOwnProperty("dob"))
{
var dateA:Date = new Date(Date.parse(itemA.dob));
var dateB:Date = new Date(Date.parse(itemB.dob));
return ObjectUtil.dateCompare(dateA, dateB);
}
else if ( itemA.hasOwnProperty("dob"))
{
return 1;
}
else if (itemB.hasOwnProperty("dob"))
{
return -1;
}
return ObjectUtil.stringCompare(itemA.name, itemB.name);
}
private function date_dataTipFunc(item:Object):String
{
if (item.hasOwnProperty("dob"))
{
return dateFormatter.format(item.dob);
}
return "";
}
private function label_dob(item:Object, col:AdvancedDataGridColumn):String
{
var dob:String="";
if(item.hasOwnProperty("dob"))
{
dob=item.dob;
}
return dob;
}
]]>
</mx:Script>
<mx:DateFormatter id="dateFormatter" formatString="MMMM D, YYYY" />
<mx:AdvancedDataGrid id="adgTest" dataProvider="{new HierarchicalData(this.arrData)}" designViewDataType="tree" width="746" height="400">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Name" dataField="name"/>
<mx:AdvancedDataGridColumn dataField="dob" headerText="Date of birth"
labelFunction="label_dob"
sortCompareFunction="date_sortCompareFunc"
showDataTips="true"
dataTipFunction="date_dataTipFunc" />
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Application>
source
share