I have a Datagrid that gets its data from an ArrayCollection of model "beans". The ArrayCollection Outcomes is a lis开发者_运维知识库t of Outcome
<s:DataGrid dataProvider="{outcomes}">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="outcome" headerText="Outcome" width="120"/>
<s:GridColumn dataField="dateRequired" headerText="Date Req" width="130"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
Outcome.as
[Bindable]
public class ASPersonalOutcomeSummary {
public var _outcome:String;
public var _dateRequired:Number;
}
The problem is that dateRequired is represented as a Number, this design decision was made so it makes it easier to pass between the AS client and Java backend.
I really want to display this number as a Date String (eg. 1 Feb 2011 or something like that) but as it is a number, it simply displays as the timestamp in the datagrid... eg.
Outcomes | Date Required
blahhhhhh | 12389712987
blahhhhh2 | 13242342349
Any ideas?
Use the labelFunction
which is something like the following:
private function dateLabelFunction(item: ASPersonalOutcomeSummary, column:GridColumn):String
{
var timeStamp:Number = item. _dateRequired;
var date:Date = new Date(timeStamp);
return new DateFormatter().format(date);
}
And then:
<s:DataGrid dataProvider="{outcomes}">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="outcome" headerText="Outcome" width="120"/>
<s:GridColumn labelFunction="dateLabelFunction" headerText="Date Req" width="130"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
You can just do new Date(_dataRequired) in a labelFunction and then format it with a dateformatter.
Cheers
精彩评论