按两列对datagrid进行排序会删除排序箭头

时间:2013-06-20 15:25:06

标签: sorting flex dataprovider columnheader

我正在使用Flex版本3.6,我需要按两列对数据网格进行排序。当我单击列标题时,排序箭头会显示在其上。

我现在要做的是当我点击1个特定列时,它将按两列排序。那部分工作。

但是我注意到通常出现在排序列上的排序箭头指示符已经消失。我正在使用DataGrid的子类,所以在我排序之后,我尝试使用placeSortArrow()但我在 DataGridHeader.as 中注意到sortArrow为空。

protected function headerReleaseListener(event:DataGridEvent):void
{
    if(event.columnIndex == 0)
    {
        event.preventDefault();

        var sort:Sort = new Sort();
        sort.fields = [new SortField("@name",true, true), new SortField("@address",true, false)];

        ArrayCollection(this.dataProvider).sort = sort;
        ArrayCollection(this.dataProvider).refresh();
    }
}

我希望拥有的是指定排序箭头应显示在哪一列上,列是否按1列或更多列排序。有谁知道这是否可行?

1 个答案:

答案 0 :(得分:2)

我在Flex: Database driven DataGrid: arrows disappearing回答的问题中找到了另一个问题中消失的排序箭头的答案:ili并根据我的代码对其进行了调整。

因为有两列已排序,内部sortIndex为-1,因此sortArrow为null。

通过选择一列来显示排序(我使用主排序列)并设置sortIndex和direction,现在会出现sortArrow

protected function headerReleaseListener(event:DataGridEvent):void
{
    if(event.columnIndex == 0)
    {
        event.preventDefault();

        var sort:Sort = new Sort();
        sort.fields = [new SortField("@name",true, true), new SortField("@address",true, false)];

        ArrayCollection(this.dataProvider).sort = sort;
        ArrayCollection(this.dataProvider).refresh();

        mx_internal::sortIndex = event.columnIndex;

        mx_internal::sortDirection = (mx_internal::sortDirection == null || mx_internal::sortDirection == "ASC") ? "DESC" : "ASC";

        placeSortArrow();
    }
}