打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Reusable Numeric Sort Method for Flex DataGrid Columns

I can’t take full credit for this since I found some version of this function out there somewhere, but since it’s not that easy to find I thought I’d repost it.

If you need to numerically sort multiple columns in a DataGrid without creating a separate method for each based on its dataField, then use this:

/** * Numerically sorts a column in the DataGrid. * * @param	fieldName	The string name for the dataField in the column that you want to sort. */private function numericSortByField(fieldName:String):Function{	return function(obj1:Object, obj2:Object):int	{		var value1:Number = (obj1[fieldName] == '' || obj1[fieldName] == null) ? null : new Number(obj1[fieldName]);		var value2:Number = (obj2[fieldName] == '' || obj2[fieldName] == null) ? null : new Number(obj2[fieldName]);		return ObjectUtil.numericCompare(value1, value2);	}}

By default, the DataGrid’s sort converts your data to strings so this ensures it’s really doing a numeric sort (and is a generic one at that).

Finish it off by making sure to set the sortCompareFunction for your columns like so:

myColumn.sortCompareFunction = this.numericSortByField("myDataField");

Tweet This Post

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
用反射的方式获取父类中的所有属性和方法
xml转换为java对象
java反射机制与动态代理(二)
DataSetHelper——操作DataSet的工具类 - Rey的技术博客 - CSD...
JQuery DataGrid 中文文档
Mybatis返回Map的一种实现
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服