[flexcoders] FLEX2: Date Cell Renderer Solved

2005-10-25 Thread Greg Johnson
It looks like :)

Ok, here is what I did.  First in the MXML I created a Currency 
Formater.



Then in the dataGrid for the column I wanted to format I used the 
labelFunction parameter



and in my Actionscript file I created a function.

import mx.controls.gridclasses.DataGridColumn;
public function formatNumber(dpItem:Object, 
dgColumn:DataGridColumn):String {
return StdMoneyFormat.format(dpItem[dgColumn.columnName]);
}

unlike cellRenderer, in a dataGrid (**only**) the labelFunction 
passes 2 items.  The std dataObject that cellRenderer passes and 
specificaly the column information.  So I just do a simple return of 
the dataObject indexed by the columnName in the dataGridColumn object.

Just as a note, there is also a columnNumber in the dataGridColum 
object that would do exactly the same, just with the numerical index 
value vs the enumerated index value.

This should work for all the data Formaters includeing Date.

**only** = Acording to the documentation, anything else that uses the 
labelFunction only gets the dataObject since they are 1 dimential 
arrays vs 2 dimentional grids.  Plus if you specify one of the drop 
in renderers it will adjust in all cases to send what they need.  As 
I understand it.
--- In flexcoders@yahoogroups.com, "Greg Johnson" <[EMAIL PROTECTED]> 
wrote:
>
> Think i replyed to the wrong addy since it hasn't shown up in the 
> list.  
> 
> Is there some code somewhere I can look at that specificaly is 
> redering the date.  I have messed around and can get a datefield 
box 
> to show, but I don't need to have it edit, I just need to display 
the 
> date mm/dd/.  I have also written my own mxml and still nogo.
> 
> --- In flexcoders@yahoogroups.com, Jim Laing <[EMAIL PROTECTED]> wrote:
> >
> > In Flex 2, the cell render API is totally different. For one 
thing,
> > setValue() is no longer used. For another thing, a cell render is
> > passed a "dataObject" (or something like that) value, which 
contains
> > the data to be rendered. All of the examples I've seen thus far 
are
> > straight MXML, and most are rendered inline, so you might want to 
> try
> > heading in that direction.
> > 
> > Jim
> > 
> > On 10/21/05, Greg Johnson <[EMAIL PROTECTED]> wrote:
> > > Ok, for flex 1.5 I had downloaded a nice AS file that would 
render
> > > dates in cells for me.  However dispite me updateing it to work 
in
> > > Flex 2 it doesn't.  Any ideas what I missed?
> > >
> > >
> > > /*
> > >  * DateFormatCellRenderer is a simple Label-based cell renderer 
> that
> > > displays
> > >  * its item content in a known date format.
> > >  */
> > > package {
> > > import mx.formatters.DateFormatter;
> > > import mx.controls.Label;
> > > class DateFormatCellRenderer extends Label
> > > {
> > > var getDataLabel:Function;
> > > static var dateFmt:DateFormatter;
> > >
> > > private function init() : Void
> > > {
> > > // instantiate the 1 and only date formatter 
(more
> > > efficient than
> > > // have a date formatter for every instance of 
the
> > > cell renderer).
> > > if( dateFmt == null ) {
> > > dateFmt = new DateFormatter();
> > > dateFmt.formatString = "MM/DD/";
> > > }
> > > super.initialize();
> > > }
> > >
> > > private function setValue(str:String, item:Object,
> > > sel:Boolean):Void
> > > {
> > > if( item != null ) {
> > > // format the date value in the cell
> > > this.text = dateFmt.format(item
> [getDataLabel
> > > ()]);
> > > }
> > > else {
> > > this.text = "";
> > > }
> > > }
> > >
> > > private function size() : Void
> > > {
> > > this.setActualSize
(explicitWidth,explicitHeight);
> > > }
> > > }
> > > }
> > >
> > > btw the size function change is a complete guess on my part.
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Flexcoders Mailing List
> > > FAQ: 
> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > > Search Archives: http://www.mail-archive.com/flexcoders%
> 40yahoogroups.com
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
>






 Yahoo! Groups Sponsor ~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/nhFolB/TM
~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
[EMAIL

Re: [flexcoders] FLEX2: Date Cell Renderer

2005-10-21 Thread Jim Laing
In Flex 2, the cell render API is totally different. For one thing,
setValue() is no longer used. For another thing, a cell render is
passed a "dataObject" (or something like that) value, which contains
the data to be rendered. All of the examples I've seen thus far are
straight MXML, and most are rendered inline, so you might want to try
heading in that direction.

Jim

On 10/21/05, Greg Johnson <[EMAIL PROTECTED]> wrote:
> Ok, for flex 1.5 I had downloaded a nice AS file that would render
> dates in cells for me.  However dispite me updateing it to work in
> Flex 2 it doesn't.  Any ideas what I missed?
>
>
> /*
>  * DateFormatCellRenderer is a simple Label-based cell renderer that
> displays
>  * its item content in a known date format.
>  */
> package {
> import mx.formatters.DateFormatter;
> import mx.controls.Label;
> class DateFormatCellRenderer extends Label
> {
> var getDataLabel:Function;
> static var dateFmt:DateFormatter;
>
> private function init() : Void
> {
> // instantiate the 1 and only date formatter (more
> efficient than
> // have a date formatter for every instance of the
> cell renderer).
> if( dateFmt == null ) {
> dateFmt = new DateFormatter();
> dateFmt.formatString = "MM/DD/";
> }
> super.initialize();
> }
>
> private function setValue(str:String, item:Object,
> sel:Boolean):Void
> {
> if( item != null ) {
> // format the date value in the cell
> this.text = dateFmt.format(item[getDataLabel
> ()]);
> }
> else {
> this.text = "";
> }
> }
>
> private function size() : Void
> {
> this.setActualSize(explicitWidth,explicitHeight);
> }
> }
> }
>
> btw the size function change is a complete guess on my part.
>
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>
>
>
>


 Yahoo! Groups Sponsor ~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/nhFolB/TM
~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
 




[flexcoders] FLEX2: Date Cell Renderer

2005-10-21 Thread Greg Johnson
Ok, for flex 1.5 I had downloaded a nice AS file that would render 
dates in cells for me.  However dispite me updateing it to work in 
Flex 2 it doesn't.  Any ideas what I missed?


/*
 * DateFormatCellRenderer is a simple Label-based cell renderer that 
displays
 * its item content in a known date format.
 */
package {
import mx.formatters.DateFormatter;
import mx.controls.Label;
class DateFormatCellRenderer extends Label
{   
var getDataLabel:Function;
static var dateFmt:DateFormatter;

private function init() : Void
{
// instantiate the 1 and only date formatter (more 
efficient than
// have a date formatter for every instance of the 
cell renderer).
if( dateFmt == null ) {
dateFmt = new DateFormatter();
dateFmt.formatString = "MM/DD/";
}
super.initialize();
}

private function setValue(str:String, item:Object, 
sel:Boolean):Void
{
if( item != null ) {
// format the date value in the cell
this.text = dateFmt.format(item[getDataLabel
()]);
}
else {
this.text = "";
}
}

private function size() : Void
{
this.setActualSize(explicitWidth,explicitHeight);
}
}
}

btw the size function change is a complete guess on my part.





 Yahoo! Groups Sponsor ~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/nhFolB/TM
~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/