首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在flex中对DatagridColumn进行排序

在flex中对DatagridColumn进行排序
EN

Stack Overflow用户
提问于 2011-10-29 07:51:43
回答 1查看 257关注 0票数 0

我在flex中有一个DatagridColumn,它有两个名称,类型和名称

现在,当我对数据列TYPE进行排序时,它使用sortcomparefunction对类型进行排序,并给出包含元素的分组和排序顺序的结果。例如。如果我对TYPE进行排序,我将得到按分组顺序排列的pdf、doc、ppt格式的元素,但它们在内部没有排序,例如:对于pdf部分,我有这样的元素: type NAME pdf A1.pdf pdf X2.pdf pdf B1.pdf

这里对文件类型进行了排序,但是对于特定的文件类型,元素没有进行排序,请注意,B1出现在X2之后,应该对其进行排序

有没有办法在根据文件类型扩展名对第一个datagridcolumn进行排序后,对第二个datagridcolumn进行排序?

我使用sortcomparefunction根据类型对元素进行排序,这很好用。签名是:

私有函数sortTheTypeColumn(itemA:Object,itemB:Object):int

EN

回答 1

Stack Overflow用户

发布于 2011-10-29 10:59:32

可能是这样的:

代码语言:javascript
复制
    protected function sortTheTypeColumn(x:Object, y:Object):int
    {
        var xType:String = String(x["TYPE"]).toLocaleLowerCase();
        var yType:String = String(y["TYPE"]).toLocaleLowerCase();

        var result:int = sortInternalCompare(xType, yType);

        if (result == 0)
        {
            var aName:String = String(x["NAME"]).toLocaleLowerCase();
            var bName:String = String(y["NAME"]).toLocaleLowerCase();

            result = sortInternalCompare(aName, bName);
        }

        return result;
    }

    protected function sortInternalCompare(x:String, y:String):int
    {
        if (x == null && y == null)
            return 0;
        if (x == null)
            return 1;
        if (y == null)
            return -1;

        var result:int = x.localeCompare(y);

        if (result < -1)
            result = -1;
        if (result > 1)
            result = 1;

        return result;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7936004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档