AdvancedDataGrid列排序问题

发布于 2024-10-02 09:44:17 字数 4423 浏览 10 评论 0原文

我正在使用 mx:advanceddatagrid,并且遇到了分组列排序的问题。我的网格的屏幕截图如下: https://i.sstatic.net/waAi7.png< /a>

我有以下类型的数据:

PRODUCT_ID PROD_NAME CATEGORY TYPE SubType SubType_descr

1             p_1          c1_y          t1
                                              t1_s1      sub_1*
                                              t1_s2      sub_2*
                                              t1_s4      sub_4* 
                                              t1_s5      sub_5* 

2             p_2          c1_x          t1
                                               t1_s1      sub_1
                                               t1_s2      sub_2
                                               t1_s3      sub_3

3             p_3          c1_x          t1
                                               t1_s1      sub_1
                                               t1_s2      sub_2*
                                               t1_s3      sub_3*

现在,数据集的类型为 arrayCollection。当 setter 触发绑定事件时,我手动将其移动到 GroupingCollection2 中;

protected function setGrouping(columnNames:Array):void{
                _groupingColumns = [];


                if (columnNames.length > 0) {
                    var _groupedData:GroupingCollection2 = new GroupingCollection2();
                    var _grouping:Grouping = new Grouping();

                    for (var i:int=0;i<columnNames.length;i++) {
                        var gc:GroupingField = new GroupingField(columnNames[i]);
                        _groupingColumns.push(gc);
                    }
                    _groupedData.source = _ds;
                    _grouping.fields = _groupingColumns;
                    _groupedData.grouping = _grouping
                    _groupedData.refresh();
                    _data = _groupedData;
                } else {
                    _data = _ds;
                }

                setGridColumns();
            }

虽然我对 Product_Id 进行分组,但我通过 labelFunction 实现了上述外观,如下所示:

col.labelFunction = function (item:Object,column:AdvancedDataGridColumn):String {
                            if (item.hasOwnProperty('GroupLabel') && item.GroupLabel != null) {
                                if (item.children.length > 0) {
                                    return item.children[0][column.dataField];
                                }
                                else {
                                    return "";
                                }
                            }   
                            else {
                                return "";
                            }       
                        }

我从服务器收到的数据如下所示 简而言之,

    PRODUCT_ID    PROD_NAME    CATEGORY    TYPE    SubType    SubType_descr
-------------------------------------------------------------------
    1             p_1          c1_y          t1    t1_s1      sub_1*
    2             p_2          c1_y          t1    t1_s2      sub_2*
    3             p_3          c1_y          t1    t1_s3      sub_3*
-------------------------------------------------------------------
    4             p_4          c1_x          t1    t1_s1      sub_1*
    5             p_5          c1_x          t1    t1_s2      sub_2*
    6             p_6          c1_x          t1    t1_s3      sub_3*

我采用所有常见的列值(产品、类别、类型)和将它们放在第一行,子行中的所有变化值(sub_type,subtype_descr)

我想在 Prod_Name、Category 和 type 列上对这个网格进行排序,但是像下面这样的东西不起作用,即使底层数据得到排序。

public var _sort_direction:Boolean = false;
            protected function adg1_headerReleaseHandler(event:AdvancedDataGridEvent):void
            {

                var sort:Sort = new Sort();
                    sort.fields = [new SortField(event.dataField, true, _sort_direction)];

                    _ds.sort = sort;
                    _ds.refresh();

                    if (DefaultGroupColumn != null && temp[0] != DefaultGroupColumn) {
                        temp.push(DefaultGroupColumn);
                    }


                    setGrouping(temp);

                    adg1.validateNow();
                    _sort_direction = !_sort_direction;
            }

非常感谢所有帮助。

I have am using an mx:advanceddatagrid and I running into a problem with grouped column sorting. A screenshot of what my grid looks like is here: https://i.sstatic.net/waAi7.png

I have the following kind of data:

PRODUCT_ID PROD_NAME CATEGORY TYPE SubType SubType_descr

1             p_1          c1_y          t1
                                              t1_s1      sub_1*
                                              t1_s2      sub_2*
                                              t1_s4      sub_4* 
                                              t1_s5      sub_5* 

2             p_2          c1_x          t1
                                               t1_s1      sub_1
                                               t1_s2      sub_2
                                               t1_s3      sub_3

3             p_3          c1_x          t1
                                               t1_s1      sub_1
                                               t1_s2      sub_2*
                                               t1_s3      sub_3*

Now, the dataset is of the type arrayCollection. I manually move it into GroupingCollection2 when a setter fires the Binding Event;

protected function setGrouping(columnNames:Array):void{
                _groupingColumns = [];


                if (columnNames.length > 0) {
                    var _groupedData:GroupingCollection2 = new GroupingCollection2();
                    var _grouping:Grouping = new Grouping();

                    for (var i:int=0;i<columnNames.length;i++) {
                        var gc:GroupingField = new GroupingField(columnNames[i]);
                        _groupingColumns.push(gc);
                    }
                    _groupedData.source = _ds;
                    _grouping.fields = _groupingColumns;
                    _groupedData.grouping = _grouping
                    _groupedData.refresh();
                    _data = _groupedData;
                } else {
                    _data = _ds;
                }

                setGridColumns();
            }

Although I am grouping on Product_Id, i achieve the above look by a labelFunction as shown below:

col.labelFunction = function (item:Object,column:AdvancedDataGridColumn):String {
                            if (item.hasOwnProperty('GroupLabel') && item.GroupLabel != null) {
                                if (item.children.length > 0) {
                                    return item.children[0][column.dataField];
                                }
                                else {
                                    return "";
                                }
                            }   
                            else {
                                return "";
                            }       
                        }

The data I recieve from the server is of the kind shown below

    PRODUCT_ID    PROD_NAME    CATEGORY    TYPE    SubType    SubType_descr
-------------------------------------------------------------------
    1             p_1          c1_y          t1    t1_s1      sub_1*
    2             p_2          c1_y          t1    t1_s2      sub_2*
    3             p_3          c1_y          t1    t1_s3      sub_3*
-------------------------------------------------------------------
    4             p_4          c1_x          t1    t1_s1      sub_1*
    5             p_5          c1_x          t1    t1_s2      sub_2*
    6             p_6          c1_x          t1    t1_s3      sub_3*

In short I am taking all the common column values (Product, Category, Type) and putting them in the first row, all the changing values in the sub-rows (sub_type, subtype_descr)

I would like to sort this gird on Prod_Name, Category and type columns as well but sonething like the following is not working, even though the underlying data gets sorted.

public var _sort_direction:Boolean = false;
            protected function adg1_headerReleaseHandler(event:AdvancedDataGridEvent):void
            {

                var sort:Sort = new Sort();
                    sort.fields = [new SortField(event.dataField, true, _sort_direction)];

                    _ds.sort = sort;
                    _ds.refresh();

                    if (DefaultGroupColumn != null && temp[0] != DefaultGroupColumn) {
                        temp.push(DefaultGroupColumn);
                    }


                    setGrouping(temp);

                    adg1.validateNow();
                    _sort_direction = !_sort_direction;
            }

all help is really appreciated.

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

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

发布评论

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

评论(1

小…红帽 2024-10-09 09:44:17

这个问题的答案非常简单,但是 Adob​​e 文档和其他一些博客让我陷入了白费力气……

for (var i:int=0;i<columnNames.length;i++) {
                        var gc:GroupingField = new GroupingField(columnNames[i]);
                            gc.compareFunction = positionCompareFunction;
                            gc.descending = sort_dir;
                        _groupingColumns.push(gc);
                    }

一位同事(感谢 Samitt)帮助我解决了这个问题。只需添加 gc.descending ,分组就会按分组列进行排序。

The answer to this was so simple, but Adobe documentation and some other blogs sent me on a wild goose chase...

for (var i:int=0;i<columnNames.length;i++) {
                        var gc:GroupingField = new GroupingField(columnNames[i]);
                            gc.compareFunction = positionCompareFunction;
                            gc.descending = sort_dir;
                        _groupingColumns.push(gc);
                    }

A colleague (thanks Samitt) helped me figure this out. Just add gc.descending and the grouping will sort on the grouped column.

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