DataGridColumn有一个属性sortCompareFunction,是用来指定排序的比较函数的。函数原型:
mySortCompareFunction(obj1:Object, obj2:Object):int
obj1 — A data element to compare.
obj2 — Another data element to compare with obj1.
The function should return a value based on the comparison of the objects:
-1 if obj1 should appear before obj2 in ascending order.
0 if obj1 = obj2.
1 if obj1 should appear after obj2 in ascending order.
Note: The obj1 and obj2 parameters are entire data provider elements and not just the data for the item.The default value is null.
实际使用的时候感觉并不是很人道,首先跟labelFunction不同,没有column:DataGridColumn参数,这样,如果有很多 column,那就不得不写同样数量的比较函数。另外,一般的排序,往往都是在比较实际显示出来的值,如果使用了LabelFunction,就很可能是 比较LabelFunction的返回值(也就是肉眼看到的显示在表格里的东东),这样也是有点繁琐,不过还是可以通过调用labelFunction再 计算一遍,比如:
private function formTable_sortFunc_access(obj1:Object, obj2:Object):int {
return ObjectUtil.stringCompare(accessField.labelFunction(obj1, accessField),
accessField.labelFunction(obj2, accessField));
}
注:accessField是DataGridColumn的id,点击header的时候才会触发排序