设置DataGrid单元格的颜色
<mx:DataGridColumn headerText="变更终验剩余工期" dataField="realdateChangeFinalcheck" labelFunction="getDays">
<mx:itemRenderer>
<mx:Component>
<mx:Label>
<mx:Script>
<![CDATA[
override public function set data(value:Object):void{
super.data = value;
if((value.realdateChangeFinalcheck as Date) != null && value.realdateChangeFinalcheck < new Date()){
this.setStyle("color","red");
}else{
this.setStyle("color","black");
}
}
]]>
</mx:Script>
</mx:Label>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="销售项目编号" dataField="projectNo" />
在第一个DataGridColumn中,实现的功能是当剩余时间为零或零以下时以红色显示。
下面是getDays方法:
/*计算到期时间距离当前时间的差距*/
private function getDays(item:Object,column:DataGridColumn):String{
if(item[column.dataField] == null){
return "";
}else{
var date1:Date = new Date();
var date2:Date = item[column.dataField];
var df:DateFormatter = new DateFormatter();
df.formatString = "YYYY-MM-DD";
date1 = DateField.stringToDate(df.format(date1),"YYYY-MM-DD");
var num1:Number = date1.valueOf();
var num2:Number = date2.valueOf();
var dif:Number = num2 -num1;
var days:Number = dif/24/60/60/1000;
return days;
}