Thanks much, Alex!
I was trying to accomplish something similar, but wasn't having much
luck getting it to work.

I'm using Hot Fix 1, and, as I mentioned, it throws an exception with
my example as well... when run under the debug player. Otherwise it
was silent. I saw the if statement in the data setter for the
DateField, noticed that there was a case for data incoming as a
string, and figured it was just a matter of getting the format correct.

Thank you again. You're a lifesaver.


--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> What version of Flex are you using?  Flex 3 Beta 2 and Flex 2.0.1
> HotFix2 (which are the only versions you should be using) both throw
> exceptions with this example.
> 
>  
> 
> DateField isn't really set up to handle XML when it is an item renderer.
> I sort of got it working like this:
> 
>  
> 
> <mx:DataGridColumn headerText="Date" dataField="date"
> 
> width="100" editable="true"
> 
> editorDataField="selectedDate" rendererIsEditor="true">
> 
> <mx:itemRenderer>
> 
>             <mx:Component>
> 
>                         <mx:DateField>
> 
>                                     <mx:Script>
> 
>                                     <![CDATA[
> 
>                                                 import
> mx.controls.listClasses.BaseListData;
> 
>                                                 import
> mx.controls.dataGridClasses.DataGridListData;
> 
>                                                 // block the underlying
> DateFields listData so it
> 
>                                                 // doesn't think it is
> in a DataGrid
> 
>                                                 private var
> _ld:BaseListData;
> 
>                                                 override public function
> get listData():BaseListData
> 
>                                                 {
> 
>                                                             return _ld;
> 
>                                                 }
> 
>  
> 
>                                                 override public function
> set listData(value:BaseListData):void
> 
>                                                 {
> 
>                                                             _ld = value;
> 
>                                                 }
> 
>  
> 
>                                                 private var _dd:Object;
> 
>                                                 override public function
> get data():Object
> 
>                                                 {
> 
>                                                             return _dd;
> 
>                                                 }
> 
>  
> 
>                                                 override public function
> set data(value:Object):void
> 
>                                                 {
> 
>                                                             _dd = value;
> 
>  
> 
>                                                             if (_ld &&
> _ld is DataGridListData)
> 
>                                                             {
> 
>  
> var s:String = value[DataGridListData(_ld).dataField].toString();
> 
>  
> trace(s);
> 
>  
> super.data = new Date(Date.parse(s));
> 
>                                                             }
> 
>                                                 }
> 
>  
> 
>                                     ]]>
> 
>                                     </mx:Script>
> 
>                         </mx:DateField>
> 
>             </mx:Component>
> 
> </mx:itemRenderer>
> 
> </mx:DataGridColumn>
> 
>  
> 
> Note that the first date in your example is not a valid format for
> Date.parse().
> 
>  
> 
> HTH,
> 
> -Alex
> 
>  
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of carl_steinhilber
> Sent: Tuesday, December 04, 2007 9:42 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Re: Using DateField as itemEditor for DataGrid
> column
> 
>  
> 
> Hi Alex,
> 
> Sure. (Holiday-themed) example below. :-) XML inline, of course,
> rather than loaded from external doc as in my final app. As is, it
> works (all data is shown, and clicking in the date field opens the
> DateField editor... there's a coercion error on click in debug, but
> it's silent when not in debug).
> 
> Changing the "date" DataGridColumn to 
> <mx:DataGridColumn headerText="Date" dataField="date"
> width="100" editable="true"
> itemRenderer="mx.controls.DateField"
> editorDataField="selectedDate" rendererIsEditor="true" /> 
> 
> prevents any data from being shown. In debug, the coercion error
> occurs immediately on creation... which makes perfect sense.
> 
> So the issue is definitely that Flex can't parse the date from the XML
> node. But I'm at a loss as to how to define the date in the XML to fix
> the problem. Am I going to have to step through the XML and convert it
> to an Object, converting the date along the way? Or is there a more
> straight-forward solution I'm missing? Would there be a way to wrap
> the DateField in a custom renderer that can convert the date on the fly?
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> "
> layout="vertical" creationComplete="init()" >
> <mx:Script>
> <![CDATA[
> import mx.collections.XMLListCollection;
> 
> [Bindable]
> private var xmlChristmas:XMLListCollection;
> 
> private function init():void
> {
> xmlChristmas = new
> XMLListCollection(xmlDaysOfChristmas.day.copy());
> }
> 
> private var xmlDaysOfChristmas:XML = 
> <root>
> <day>
> <name>First Day of Christmas</name>
> <date>2007-12-25T00:00:00.0000000-05:00</date>
> <gift>Partridge in a pear tree</gift>
> </day>
> <day>
> <name>Second Day of Christmas</name>
> <date>12/26/2007</date>
> <gift>Two turtle doves</gift>
> </day>
> <day>
> <name>Third Day of Christmas</name>
> <date>Thu Dec 27 00:00:00 GMT-0800 2007</date>
> <gift>Three french hens</gift>
> </day>
> </root>;
> ]]>
> </mx:Script>
> 
> <mx:DataGrid id="dgOutput" dataProvider="{xmlChristmas}"
> width="600" height="160" editable="true">
> <mx:columns>
> <mx:DataGridColumn headerText="Name" dataField="name"
> width="200" editable="true" />
> <mx:DataGridColumn headerText="Date" dataField="date"
> width="100" editable="true"
> itemEditor="mx.controls.DateField"
> editorDataField="selectedDate" /> 
> <!-- mx:DataGridColumn headerText="Date" dataField="date"
> width="100" editable="true"
> itemRenderer="mx.controls.DateField"
> editorDataField="selectedDate" rendererIsEditor="true" / --> 
> <mx:DataGridColumn headerText="Gift" dataField="gift"
> width="300" editable="true" /> 
> </mx:columns>
> </mx:DataGrid> 
> </mx:Application>
> 
> --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
> , "Alex Harui" <aharui@> wrote:
> >
> > Can you post a mini-example?
> > 
> > 
> > 
> > ________________________________
> > 
> > From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
> ] On
> > Behalf Of carl_steinhilber
> > Sent: Sunday, December 02, 2007 11:43 PM
> > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> > Subject: [flexcoders] Using DateField as itemEditor for DataGrid
> column
> > 
> > 
> > 
> > 
> > I'm having a problem using a DateField as a itemRenderer/editor for a
> > column in a dataGrid.
> > 
> > If I set the DateField as my itemEditor, everything works perfectly.
> > But if I set the DateField as my itemRenderer and set rendererIsEditor
> > to true the dataGrid renders completely blank (no data in *any* field)
> > and locks down so *nothing* is editable.
> > 
> > In reading posts in the archives in this group and elsewhere, folks
> > with similar issues were told to make sure the data bound to the
> > column is of type date.
> > But I have two issues with that:
> > 1) if it wasn't understood as being of type date, why would it work
> > when the dateField was set as the itemEditor
> > and
> > 2) I'm loading in the dataProvider for the DataGrid as a Bindable
> > XMLListCollection from an external XML file... and I'm not sure how I
> > can designate in XML that the node is of type date.
> > 
> > Anyone have any info or pointers? They'd be greatly appreciated.
> > 
> > Thanks in advance!
> > -Carl
> >
>


Reply via email to