我有一个使用客户数据分组的 AdvancedDataGrid。并非所有组都在层次结构中处于同一级别,组可以同时包含组和成员。我们有一个排序回调,但除了最叶级别的组外,它不会被调用。有关示例,请参见下面的代码 - 展开所有组,然后单击“出生日期”上的排序列以按出生日期进行反向排序。(奇怪的是,出于某种深不可测的原因,第一个升序排序有效。)
我们不会因与组成员处于同一级别分组的任何数据而被调用。
我该如何解决?
谢谢。
<?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>