3

I have a Datagrid that gets its data from an ArrayCollection of model "beans". The ArrayCollection Outcomes is a list 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?

p_mcp
  • 2,643
  • 8
  • 36
  • 75

2 Answers2

4

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>
Constantiner
  • 14,231
  • 4
  • 27
  • 34
2

You can just do new Date(_dataRequired) in a labelFunction and then format it with a dateformatter.

Cheers

Dennis Jaamann
  • 3,547
  • 2
  • 23
  • 42