[flexcoders] Re: Overriding text display in DataGridItemRenderer

2008-10-09 Thread karlgold
Thanks very much Tracy, that's exactly what I was missing.  For the
record, here's the label function:

package com.myco.components {

 import mx.controls.dataGridClasses.DataGridColumn;
 import mx.formatters.DateFormatter;

 public class DateRenderer {

 private var _formatter:DateFormatter

 public function DateRenderer() {

 super();

 _formatter = new DateFormatter();
   _formatter.formatString=EEE, DD MMM  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-);

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

 public function render( data:Object, column:DataGridColumn ) :
String  {

   if (! data) { return n.a.; }

   var dateString:String = data[column.dataField];

   if (! dateString) { return n.a.; }

   var date:Date = isoToDate(String(dateString));
   return _formatter.format(date);
 }
 }
}

I create an instance of this in my subclass of DataGrid, and then just
set
the labelFunction property of date columns to _dateRenderer.render.

--- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote:

 If really all you want to do is,  override the text, then this is
 overkill.  Just use a labelFunction().

 But if you want to do an item renderer, I should think you would set
 the display in the set data() override.  Well, rather in the the
 commitProperties function, after invalidating properties in set data
 ().

 Tracy

 --- In flexcoders@yahoogroups.com, karlgold karlgold@ wrote:
 
  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  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-);
 
 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
 




[flexcoders] Re: Overriding text display in DataGridItemRenderer

2008-09-29 Thread Tracy Spratt
If really all you want to do is,  override the text, then this is 
overkill.  Just use a labelFunction().

But if you want to do an item renderer, I should think you would set 
the display in the set data() override.  Well, rather in the the 
commitProperties function, after invalidating properties in set data
().

Tracy

--- In flexcoders@yahoogroups.com, karlgold [EMAIL PROTECTED] wrote:

 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  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-);
 
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