나는 그런 일이 왜 정확히 모르겠어요. 그러나,
otherValue
에 의해
value
및에 의해
childData
에서 elmenents를 정렬 할 수 있을까 ... 그 자식 컬렉션에 상속
sort
처럼 보인다? 이 경우
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
를 작성하는 것입니다.