根据DataGridColumn的labelFunction的结果进行排序等操作
(1)/*计算到期时间距离当前时间的差距*/
private function getDays(item:Object,column:DataGridColumn):String{
if(item[column.dataField] == null){
return "";
}else{
var df:DateFormatter = new DateFormatter();
df.formatString = "YYYY-MM-DD";
var num1:Number = 0; //当前时间或实际终验时间
var num2:Number = 0;//当前所在列时间
var dif:Number = 0;
var days:Number = 0;
var date1:Date = null;//当前时间或实际终验时间
var date2:Date = item[column.dataField];//当前所在列时间
//实际终止时间不为空
if(item["realdateFinalcheck"] != null && item["realdateFinalcheck"] != ""){
date1 = DateField.stringToDate(df.format(item["realdateFinalcheck"]),"YYYY-MM-DD");
num1 = date1.valueOf();
}
//实际终止时间为空
else{
date1 = new Date();
date1 = DateField.stringToDate(df.format(date1),"YYYY-MM-DD");
num1 = date1.valueOf();
}
num2 = date2.valueOf();
dif = num2 -num1;
days = dif/24/60/60/1000;
return days;
}
}
(2) /*****************************
* 给时间差距排序
* ***/
private function compareFunctionContractInit(obj1:Object,obj2:Object):int{
return ObjectUtil.numericCompare(getDays(obj1,edateContractPrecheckId),getDays(obj2,edateContractPrecheckId));
}
(3)DataGridColumn调用排序的方法:sortCompareFunction="compareFunctionContractInit"