AdvancedDataGrid 多列编程排序

发布于 2024-07-29 03:14:37 字数 263 浏览 8 评论 0原文

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

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

非常感谢您的帮助,

谢谢:)

I need to to a programmatic multi column sorting on the AdvancedDataGrid.
The issue is, currently I am implementing paging on my grid. So, if I sort the data, only the perticular page is being sorted. So, I need to sort the entire list by the column criteria.

I tried HeaderRelease event, but I guess it is of no use as I need to make a round trip call to the server to get the sorted data. Is there any way I can implement that. I also need to show the sort markers in the Column headers' right position, indicating the sort numbers and direction.

'll really appreciate the help

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

执笏见 2024-08-05 03:14:37

您需要扩展 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(',');
}

You need to extend the AdvancedDataGrid and override the 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(',');
}
时光暖心i 2024-08-05 03:14:37

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

If your data is paged, you'll have to go to the server to retrieve the data anyways. If only a portion of the data is stored client side, it might be better to just sort on the server, since only the server will have all the data.

蓝戈者 2024-08-05 03:14:37

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

        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>

Create your own custom Advance Datagrid as given in the example below.
You have the array of sorted columns and the order. Send a cutom event and pass this array to it. The server side Tech will make the query accordingly and return you the result.

        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>

空城旧梦 2024-08-05 03:14:37

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

<: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>

SORRY Guys!! Missed the inital part of the code.... Here is the right code

<: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>
月野兔 2024-08-05 03:14:37

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

protected function dataGrid_initializeHandler(event:FlexEvent):void {
    dataGrid.addEventListener(AdvancedDataGridEvent.SORT, dataGrid_sortHandler, false, -50);
}

protected function dataGrid_sortHandler(event:FlexEvent):void {
    dataGrid.dataProvider.sort; // now up to date!
}


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

Try modifiyng the event priority of the sort event, no need to override the sort handler, but can't be done in mxml.

protected function dataGrid_initializeHandler(event:FlexEvent):void {
    dataGrid.addEventListener(AdvancedDataGridEvent.SORT, dataGrid_sortHandler, false, -50);
}

protected function dataGrid_sortHandler(event:FlexEvent):void {
    dataGrid.dataProvider.sort; // now up to date!
}


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

浮生未歇 2024-08-05 03:14:37

您还可以查看 AdvancedDataGridSortItemRenderer 类。 这有助于自定义排序项渲染器。

You can also have a look at the AdvancedDataGridSortItemRenderer class. This helps to customise the sort item renderer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文