I'm trying to implement a custom item renderer in ActionScript that
parses an ISO date string (which is the way the date is always
represented in my data feed) and formats it for display in a DataGrid
column.

I have tried multiple variations on this:

package com.mycompany.components {

   import mx.controls.dataGridClasses.DataGridItemRenderer;
   import mx.controls.dataGridClasses.DataGridListData;
   import mx.controls.listClasses.BaseListData;
   import mx.formatters.DateFormatter;

   public class DateRenderer extends DataGridItemRenderer    {

     private var _formatter:DateFormatter

     public function DateRenderer() {

       super();

       _formatter = new DateFormatter();
       _formatter.formatString="EEE, DD MMM YYYY at LL:NN A";
     }

     private function isoToDate(value:String):Date {

       var dateStr:String = value;

       dateStr = dateStr.replace(/-/g, "/");
       dateStr = dateStr.replace("T", " ");
       dateStr = dateStr.replace("Z", " GMT-0000");

       return new Date(Date.parse(dateStr));
     }

     override public function set listData( row:BaseListData ) : void {

       super.listData = row;

       var data:String = row.label;
       if (data) {
         var date:Date = isoToDate(data);
         super.text = _formatter.format(date);
       } else {
         super.text = "n.a.";
       }

       super.invalidateDisplayList();
     }
   }
}

However, the data grid always displays the raw ISO date rather than the
formatted one.

I stepped through the code and noticed that
DataGridItemRenderer.validateProperties() always sets the text property
to _listData.label.  I can see my formatted text value getting reset to
the raw data value every time.

Is there some way around this short of copying and hacking up my own
version of DGIR?

I also tried extending Label; this displayed the formatted date but all
the normal mouse behaviors (highlighting on mouseover, selecting on
click) stopped working in that column.  Really all I want to do is
override the text that DGIR displays.

Thanks for any guidance,

Karl

Reply via email to