The flex code that you are interested in is in DataGrid.as...
private function itemEditorItemEditEndHandler(event:DataGridEvent):void

In this code the new value in editorDataField property is assigned over to your itemRenderer.data as follows

if (itemEditorInstance && event.reason != DataGridEventReason.CANCELLED)
           {
var newData:Object = itemEditorInstance[_columns[event.columnIndex].editorDataField];
               var property:String = _columns[event.columnIndex].dataField;
               var data:Object = event.itemRenderer.data;
               var typeInfo:String = "";
               for each(var variable:XML in describeType(data).variable)
               {
                   if (property == [EMAIL PROTECTED]())
                   {
                       typeInfo = [EMAIL PROTECTED]();
                       break;
                   }
               }

               if (typeInfo == "String")
               {
                   if (!(newData is String))
                       newData = newData.toString();
               }
               else if (typeInfo == "uint")
               {
                   if (!(newData is uint))
                       newData = uint(newData);
               }
               else if (typeInfo == "int")
               {
                   if (!(newData is int))
                       newData = int(newData);
               }
               else if (typeInfo == "Number")
               {
                   if (!(newData is int))
                       newData = Number(newData);
               }
               if (data[property] != newData)
               {
                   bChanged = true;
                   data[property] = newData;
               }
               if (bChanged && !(data is IPropertyChangeNotifier))
               {
                   collection.itemUpdated(data, property);
               }
               if (event.itemRenderer is IDropInListItemRenderer)
               {
var listData:DataGridListData = DataGridListData(IDropInListItemRenderer(event.itemRenderer).listData); listData.label = _columns[event.columnIndex].itemToLabel(data); IDropInListItemRenderer(event.itemRenderer).listData = listData;
               }
               event.itemRenderer.data = data;
           }

So... given the following  you should be able to get this to work

1) Object in your ArrayCollection with property dateMS:Number. If you have a strongly typed object in there, then you can write a set dateMS(newDateMS:Number):void method in this class and set a breakpoint on it in the debugger... that will help you determine what the editor is passing to you on item edit end. If you don't have a strongly typed object, you will just have to watch the property.

2) Subclass of DateField with an additional property dateMS:Number
... you will also need a set dateMS(newDateMS:Number) in this class that sets the data property of the editor to a date that is using your newDateMS value.

3) datagrid column definition with dataField="dateMS" and editorDataField="dateMS"

The itemEditEnd handler should then take the value from your editor "dateMS" property and assign it over to YourClass.dateMS on item edit end as a Number.

BTW: I pass all dates between back-end and front-end as millis as well, but I always construct dates when I read them in from results and store in AS objects as Date type. So... i have not done what you are trying to do, but it does seem do-able. I don't see anything in the code above that should prevent it.

hth
Scott


j_lentzz wrote:

That is one of the approaches I tried. I added a property called
dateInMs, set the editorDataField to that name, and then overrode the
get/set data, like what you mentioned. I could get it to display the
correct date, but whenever I edited it, it would end up displaying
NaN/Nan/Nan for the formatted date. I could see the millisec being
changed to dates in the arraycollection (which isn't what I wanted),
but I haven't been able to get them to stay millisec in the array
collection, but display/edit as date objects. Very frustrating.

John
--- In [email protected] <mailto:flexcoders%40yahoogroups.com>, Scott - FastLane <[EMAIL PROTECTED]> wrote:
>
> John -
>
> The problem is likely related to the DataGridColumn.editorDataField
> property. If you are using DateField etc. for an editor this property
> is "data" and it assumes that you will be assigning a Date object or a
> String that is in a format that the Date class can parse. (as shown in
> code snippet below).
>
> It seems you would have to extend DateField and override set
> data(object:Value) or add a new property like dateMillis:Number then
set
> your column to have editorDataField="dateMillis", then write the
> necessary code in your customized editor class.
>
> hth
> Scott
>
> --- From DateField.as ---
> public function set data(value:Object):void
> {
> var newDate:Date;
>
> _data = value;
>
> if (_listData && _listData is DataGridListData)
> newDate = _data[DataGridListData(_listData).dataField];
> else if (_listData is ListData &&
ListData(_listData).labelField
> in _data)
> newDate = _data[ListData(_listData).labelField];
> else if (_data is String)
> newDate = new Date(Date.parse(data as String));
> else
> newDate = _data as Date;
>
> if (newDate && !selectedDateSet)
> {
> selectedDate = newDate;
> selectedDateSet = false;
> }
>
> dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
> }
>
>
> j_lentzz wrote:
> >
> > Hi,
> >
> > I've been pounding away at a problem dealing with DataGrids and
> > DateFields for a few days now. The problem is that I want to send and
> > receive Dates from the server using milliseconds. However, in the
> > data grid I want to display and edit Dates in MM/DD/YYYY format. One
> > solution is to convert milliseconds to Dates and from Dates to
> > milliseconds right as I send or receive data - and let the datagrid
> > deal just with Dates. That is what I finally did to get it to work.
> > What I would rather do is to not have to convert the data at the
> > service calls/results, but to let the datagrid renderer and editors
> > handle the conversion as necessary. However, I tried changing the
> > get/set data methods on the DateField (the editor) and the
> > Label/TextField (the renderer), but could never get something to work
> > that would both display the Date and edit it in the correct format. I
> > thought I was understanding which methods need to be modified, but I
> > realize I'm not. Could someone please help me understand which
> > methods need to be changed to allow for the data to be stored in
> > milliseconds in the Array Collection, but be displayed and edited in
> > the Date format?
> >
> > Thank you very much for any help,
> >
> > John
> >
> >
>


Reply via email to