0

我需要在 AdvancedDataGrid 上进行编程的多列排序。问题是,目前我正在我的网格上实现分页。因此,如果我对数据进行排序,则仅对特定页面进行排序。所以,我需要按列标准对整个列表进行排序。

我尝试了 HeaderRelease 事件,但我想它没有用,因为我需要对服务器进行往返调用以获取排序数据。有什么办法可以实现。我还需要在列标题的正确位置显示排序标记,指示排序编号和方向。

非常感谢帮助

谢谢 :)

4

6 回答 6

1

您需要扩展 AdvancedDataGrid 并覆盖 sortHandler

public var orderBy:String; 
override protected function sortHandler(event:AdvancedDataGridEvent):void {
     super.sortHandler(event); 
     var arry:Array = [];  
     for each(var o:SortField in collection.sort.fields){
         arry.push(o.name+' '+(o.descending?'DESC':'ASC'));     
     }
     orderBy = arry.join(',');
}
于 2009-08-20T20:29:51.463 回答
0

创建您自己的自定义高级数据网格,如下例所示。您有排好序的列数组和顺序。发送一个自定义事件并将这个数组传递给它。服务器端技术将相应地进行查询并返回结果。

        import mx.events.CollectionEvent;
        import mx.binding.utils.BindingUtils;
        import mx.collections.SortField;
        import mx.collections.Sort;
        import mx.collections.ArrayCollection;
        import mx.events.AdvancedDataGridEvent;

        private var sortOrder:Boolean = true;
        [Bindable]
        public var headerHt:int = 30;


        [Inspectable(defaultValue="true", type="Boolean", enumeration="true,false", inherit="yes")]
        [Bindable]
        public var allowHeaderWordWrap:Boolean = true;

        public function sortCaseInsensitive(event:AdvancedDataGridEvent):void{
            var genericDataProvider:Object  = this.dataProvider as Object;
            sortOrder = !sortOrder; 
            //genericDataProvider.sort = new Sort();
            if(genericDataProvider.sort == null){
                genericDataProvider.sort = new Sort();
            } 
            var sortField:SortField = new SortField(event.dataField,true,sortOrder);
            switch (event.dataField) {
                  case "assmtId":
                      sortField.numeric = true;
                break;

            }//switch

            //genericDataProvider.sort.fields = [sortField];
            if(genericDataProvider.sort.fields == null){
                genericDataProvider.sort.fields = [sortField];
            }else{
                //if dataField is not already present in sort fields array 
                if(genericDataProvider.sort.fields.indexOf(sortField) != -1){
                    genericDataProvider.sort.fields = genericDataProvider.sort.fields.concat(sortField);
                }
             }
            genericDataProvider.refresh();

                 // Send custom event to server and pass the array of sort to it the server side technology will make dynamic query and return the result
        }//sortCaseInsensitive

    ]]>
</mx:Script>

于 2009-09-08T07:26:52.783 回答
0

对不起大家!!错过了代码的初始部分......这是正确的代码

<:AdvancedDataGrid headerWordWrap="{allowHeaderWordWrap}"   headerRelease="sortCaseInsensitive(event)" headerHeight="{headerHt}">

    <:Script>
        <[CDATA[
            import mx.events.CollectionEvent;
                import mx.binding.utils.BindingUtils;
                import mx.collections.SortField;
                import mx.collections.Sort;
                import mx.collections.ArrayCollection;
                import mx.events.AdvancedDataGridEvent;

                private var sortOrder:Boolean = true;
                [Bindable]
                public var headerHt:int = 30;


                [Inspectable(defaultValue="true", type="Boolean", enumeration="true,false", inherit="yes")]
                [Bindable]
                public var allowHeaderWordWrap:Boolean = true;

                public function sortCaseInsensitive(event:AdvancedDataGridEvent):void{
                var genericDataProvider:Object  = this.dataProvider as Object;
                        sortOrder = !sortOrder; 
                        //genericDataProvider.sort = new Sort();
                        if(genericDataProvider.sort == null){
                                genericDataProvider.sort = new Sort();
                        } 
                        var sortField:SortField = new SortField(event.dataField,true,sortOrder);
                switch (event.dataField) {
                      case "assmtId":
                      sortField.numeric = true;
                break;

                }//switch

                //genericDataProvider.sort.fields = [sortField];
                if(genericDataProvider.sort.fields == null){
                        genericDataProvider.sort.fields = [sortField];
                }else{
                        //if dataField is not already present in sort fields array 
                        if(genericDataProvider.sort.fields.indexOf(sortField) != -1){
                                genericDataProvider.sort.fields = genericDataProvider.sort.fields.concat(sortField);
                        }
                 }
            genericDataProvider.refresh();

                 // Send custom event to server and pass the array of sort to it the server side technology will make dynamic query and return the result
                }//sortCaseInsensitive

        ]]>
<:Script>
<:AdvancedDataGrid>
于 2009-09-08T07:37:43.497 回答
0

如果您的数据被分页,则无论如何您都必须去服务器检索数据。如果只有一部分数据存储在客户端,最好只在服务器上排序,因为只有服务器拥有所有数据。

于 2009-07-30T15:29:46.247 回答
0

你也可以看看AdvancedDataGridSortItemRenderer课堂。这有助于自定义排序项渲染器。

于 2010-02-01T16:55:44.880 回答
0

尝试修改排序事件的事件优先级,不需要重写排序处理程序,但不能在mxml中完成。

受保护的函数 dataGrid_initializeHandler(event:FlexEvent):void {
    dataGrid.addEventListener(AdvancedDataGridEvent.SORT, dataGrid_sortHandler, false, -50);
}

受保护的函数 dataGrid_sortHandler(event:FlexEvent):void {
    dataGrid.dataProvider.sort; // 现在是最新的!
}


<mx:AdvancedDataGrid id="dataGrid" initialize="dataGrid_initializeHandler(event)" dataProvider="{model.dataProvider}" />

于 2010-07-14T15:02:31.420 回答