Flex:数据库驱动的 DataGrid:箭头消失

发布于 2024-07-09 15:29:46 字数 808 浏览 9 评论 0原文

在 Flex 中,我使用以下代码来允许在 DataGrid 中进行排序(数据在服务器端进行分页和排序)。

        private function headerReleaseHandler(event:DataGridEvent):void
        {
            var column:DataGridColumn = DataGridColumn(event.currentTarget.columns[event.columnIndex]);

            if(this.count>0)
            {
                if(this.query.SortField == column.dataField)
                {
                    this.query.SortAscending = !this.query.SortAscending;
                }
                else
                {
                    this.query.SortField = column.dataField;
                    this.query.SortAscending = true;
                }
                this.fill();
            }

            event.preventDefault();
        }

除了未显示指示排序的箭头之外,这工作得很好。 我怎样才能做到这一点?

谢谢! /尼尔斯

In Flex I'm using the following code to allow sorting in a DataGrid (the data is paged and sorted serverside).


        private function headerReleaseHandler(event:DataGridEvent):void
        {
            var column:DataGridColumn = DataGridColumn(event.currentTarget.columns[event.columnIndex]);

            if(this.count>0)
            {
                if(this.query.SortField == column.dataField)
                {
                    this.query.SortAscending = !this.query.SortAscending;
                }
                else
                {
                    this.query.SortField = column.dataField;
                    this.query.SortAscending = true;
                }
                this.fill();
            }

            event.preventDefault();
        }

This works perfectly, except that the arrows that indicate sorting isn't shown. How can I accomplish that?

Thanks!
/Niels

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

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

发布评论

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

评论(3

吃→可爱长大的 2024-07-16 15:29:46

如果这就是您正在寻找的内容,这里有一个示例:
http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click- a-column/

看起来您需要刷新数据提供者使用的集合。

There is an example here if this is what you are looking for:
http://blog.flexexamples.com/2008/02/28/displaying-the-sort-arrow-in-a-flex-datagrid-control-without-having-to-click-a-column/

It looks like you need to refresh the collection used by your dataprovider.

乖不如嘢 2024-07-16 15:29:46

我遇到了同样的问题,我找到的唯一解决方案是覆盖 DataGrid 并创建一个自定义的。
类如下:

public class DataGridCustomSort extends DataGrid
{

    public function DataGridCustomSort()
    {
        super();

        addEventListener(DataGridEvent.HEADER_RELEASE,
            headerReleaseHandlerCustomSort,
            false, EventPriority.DEFAULT_HANDLER);
    }       

    public function headerReleaseHandlerCustomSort(event:DataGridEvent):void {
        mx_internal::sortIndex = event.columnIndex;
        if (mx_internal::sortDirection == null || mx_internal::sortDirection == "DESC")
            mx_internal::sortDirection = "ASC";
        else
            mx_internal::sortDirection = "DESC";
        placeSortArrow();
    }

}

当您获取 HEADER_RELEASE 事件并设置列索引和方向信息时,您必须专门调用 placeSortArrow() 方法。

I have encountered the same problem and the only solution I found was to override the DataGrid and create a custom one.
Here is the class:

public class DataGridCustomSort extends DataGrid
{

    public function DataGridCustomSort()
    {
        super();

        addEventListener(DataGridEvent.HEADER_RELEASE,
            headerReleaseHandlerCustomSort,
            false, EventPriority.DEFAULT_HANDLER);
    }       

    public function headerReleaseHandlerCustomSort(event:DataGridEvent):void {
        mx_internal::sortIndex = event.columnIndex;
        if (mx_internal::sortDirection == null || mx_internal::sortDirection == "DESC")
            mx_internal::sortDirection = "ASC";
        else
            mx_internal::sortDirection = "DESC";
        placeSortArrow();
    }

}

You have to specifically call the placeSortArrow() method when you get the HEADER_RELEASE event and set the column index and direction information.

我纯我任性 2024-07-16 15:29:46

在上面的代码中,“this”指的是数据网格,因为我对 this.query.SortField 感到困惑,我假设“this”和“query”是您自己的自定义对象。以及您为什么要检查计数。这算什么


-莫汉

in the above code what does "this" refer to is it the datagrid because I am confused by this.query.SortField , I am assuming 'this' and "query' are your own custom objects. and why are you checking for count. what count is that.

Regards
-Mohan

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