AdvancedDataGrid 사용자 정의 정렬

6419 단어 datagrid
AdvancedDataGrid 사용자 정의 정렬 문제 전에 DataGrid에 정렬 방법을 썼습니다.
public function sortList(colName:String,sortType:String):void{
var sortField:SortField;  
this.colName = colName;
if(sortType=="desc"){  
sortField = new SortField(colName);
sortField.descending = true;
}
if(sortType=="asc"){
sortField = new SortField(colName);
sortField.descending = false;
}  
var sort:Sort = new Sort();  
sort.fields = [sortField];

dpFlat.sort = sort;
dpFlat.refresh();
}

사용하기는 좋지만 Advanced DataGrid에서는 이 방법이 잘 안 됩니다.
내 생각은, Advanced DataGrid에서 그룹을 흐트러뜨리지 않고 어떤 열을 정렬하는 것이다. 어떻게 실현해야 하는가?
----------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> 
    <mx:Script>  
        <![CDATA[
            import mx.controls.DateField;
            import mx.events.AdvancedDataGridEvent;
            import mx.collections.Sort;
            import mx.collections.SortField;
            import mx.utils.ObjectUtil;   
            import mx.collections.ArrayCollection;  
            import mx.collections.Grouping;
            import mx.collections.GroupingCollection;
            import mx.collections.GroupingField;
            import mx.controls.Alert;
             //include "SimpleFlatData.as" 
             [Bindable]
             public var dpFlat:ArrayCollection = new ArrayCollection([ 
              {Name:"name", Region:"Southwest", Territory:"Northern California", Territory_Rep:"T.R. Smith", Actual:55498, Estimate:50000}, 
              {Name:"name", Region:"Southwest", Territory:"Southern California", Territory_Rep:"Alice Treu", Actual:44985, Estimate:8000}, 
              {Name:"name", Region:"Southwest", Territory:"Arizona", Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
              {Name:"name", Region:"Southwest", Territory:"Abc", Territory_Rep:"Dana Binn", Actual:29885, Estimate:20000},
              {Name:"name", Region:"Southwest", Territory:"Central California",  Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}, 
              {Name:"name", Region:"Southwest", Territory:"evada", Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}, 
              {Name:"name", Region:"Southwest", Territory:"Northern California", Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
              {Name:"name", Region:"Southwest", Territory:"Srthern California", Territory_Rep:"Bauren Ipsum", Actual:38805, Estimate:40000}, 
               {Name:"name", Region:"Southwest", Territory:"Vrthern California", Territory_Rep:"Fauren Ipsum", Actual:38805, Estimate:40000}, 
              {Name:"name", Region:"Southwest", Territory:"Southern California", Territory_Rep:"Jane Grove", Actual:44913, Estimate:9000}]);
            
        public function numericCompareFunc(itemA:int, itemB:int):int 
        {
            return ObjectUtil.numericCompare(itemA, itemB);
        }
        public function stringCompareFunc(itemA:String, itemB:String):int 
        {
            return ObjectUtil.stringCompare(itemA, itemB);
        }
       public function myCompare(a:Object, b:Object, fields:Array=null):int
        {
            var result:int = 0;
            var i:int = 0;
            var propList:Array = ["Estimate","Territory"];
            var len:int = propList.length;
            var propName:String;
            while (result == 0 && (i < len))
            {
                propName = propList[i];
                if (propName == "Estimate") {
                    result = numericCompareFunc(a[propName], b[propName]);
                } else {
                    result = stringCompareFunc(a[propName], b[propName]);
                }
                i++;
            }
            return result;
        }
        public function sortTerritory():void
        {
             gc.grouping.compareFunction = myCompare;
             gc.refresh();
        }
      ]]>
    </mx:Script> 
    <mx:GroupingCollection id="gc" source="{dpFlat}" >
        <mx:Grouping >
            <mx:GroupingField id="gf" name="Estimate" caseInsensitive="true" />
        </mx:Grouping>
    </mx:GroupingCollection>
    <mx:AdvancedDataGrid id="myADG"  width="100%" height="100%" 
        dataProvider="{gc}"
        initialize="{gc.refresh()}"
        displayItemsExpanded="true"
        creationComplete="{myADG.expandAll()}" 
        defaultLeafIcon="{null}"
        folderOpenIcon="{null}"
        folderClosedIcon="{null}">
        <mx:groupedColumns>
            <mx:AdvancedDataGridColumn dataField="Region"/>
            <mx:AdvancedDataGridColumn dataField="Territory" />
            <mx:AdvancedDataGridColumn dataField="Territory_Rep" headerText="Territory Rep" sortable="false"/>
            <mx:AdvancedDataGridColumn dataField="Actual" visible="false" />
            <mx:AdvancedDataGridColumn dataField="Estimate" sortable="false"/>
        </mx:groupedColumns>
    </mx:AdvancedDataGrid>
    <mx:Button label=" Territory " click="sortTerritory()"/>
</mx:Application>

Grouping Collection에서 array Collation item Update가 작용하려면 반드시 gc를 추가해야 합니다.refresh()

좋은 웹페이지 즐겨찾기