Flex:关于DataGridColumn 的sortCompareFunction 的问题 [英] Flex: question about the sortCompareFunction of the DataGridColumn

查看:11
本文介绍了Flex:关于DataGridColumn 的sortCompareFunction 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何我可以对多列使用相同的 sortCompareFunction 而不是为每列添加一个函数,因为我有一个包含 50 列的数据网格,其中 40 列的 dataField 不是字符串或数字,它是一个数组,所以列的默认排序不起作用.并根据adobe help 的sortCompareFunction的两个参数是整个数据提供者元素,而不仅仅是项目的数据,所以这意味着我必须为每一列定义 40 个排序函数.还有其他解决办法吗?

Is there anyway I could use the same sortCompareFunction for multiple columns instead of adding a function for each column, as I have a datagrid with 50 columns in which the dataField of 40 columns is not string or number, it's an array so the default sorting of the column won't work. And according to adobe help the two parameters of the sortCompareFunction are entire data provider elements and not just the data for the item, so this means I have to define 40 sort functions one for each column. Is there any other solution?

提前致谢.

推荐答案

你可以这样指定排序函数:

You could specify sort function like that:

<mx:DataGridColumn dataField="someFieldName"
    sortCompareFunction="{function(ob1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'someFieldName');}}"/>

其中 mySortFunc 是这样实现的:

where mySortFunc is implemented like that:

private function mySortFunc(obj1:Object, obj2:Object, fieldName:String):int{
    if (obj1.hasOwnProperty(fieldName) && obj2.hasOwnProperty(fieldName)){
        //comparison logic ex.
        return obj1[fieldName]>obj2[fieldName]?1:(obj1[fieldName]<obj2[fieldName]?-1:0);
    }
}

这样您就可以拥有一个功能来满足您所有的排序需求:)

This way you can have one function for all your sorting needs :).

这篇关于Flex:关于DataGridColumn 的sortCompareFunction 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆