我不完全确定它为什么会发生。然而,它看起来像sort
继承至其子集...
是否有可能通过otherValue
value
和在childData
的elmenents排序?在这种情况下,您可以使用IHierarchicalCollectionView
对所有元素进行排序。看看下面的例子:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" initialize="init()">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.HierarchicalCollectionView;
import mx.collections.HierarchicalData;
import mx.collections.IHierarchicalCollectionView;
import mx.collections.Sort;
import mx.collections.SortField;
private var records:ArrayCollection = new ArrayCollection([
new Data("S", null, new ArrayCollection([
new Data(null, "R", null),
new Data(null, "B", null),
new Data(null, "L", null)
])),
new Data("A", null, new ArrayCollection([
new Data(null, "P", null),
new Data(null, "O", null)
])),
new Data("X", null, new ArrayCollection([
new Data(null, "C", null),
new Data(null, "F", null),
new Data(null, "E", null)
]))
]);
[Bindable]
private var hierarchicalView:IHierarchicalCollectionView;
private function init():void
{
var hierarchicalRecords:HierarchicalData = new HierarchicalData(records);
// you don't need this if your field is named 'children' which is the default...
hierarchicalRecords.childrenField = "childrenData";
hierarchicalView = new HierarchicalCollectionView(hierarchicalRecords);
sortData(hierarchicalView);
}
private function sortData(view:IHierarchicalCollectionView):void
{
var x:ArrayCollection;
view.sort = new Sort();
view.sort.fields = [new SortField('value', true, false), new SortField('otherValue', true, false)];
view.refresh();
}
]]>
</fx:Script>
<s:layout>
<s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
</s:layout>
<mx:AdvancedDataGrid designViewDataType="tree" height="80%" dataProvider="{hierarchicalView}"
creationComplete="event.currentTarget.expandAll()">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="value"/>
<mx:AdvancedDataGridColumn dataField="otherValue"/>
</mx:columns>
</mx:AdvancedDataGrid>
</s:Application>
另一种选择是写一个compareFunction
,你的对象相应的比较。