Select to view content in your preferred language

Datagrid Formatting

833
3
02-23-2011 02:34 PM
JasonNielsen
Regular Contributor
I have a custom built application and it contains a datagrid that has a dataprovider of a Query and several different fields are returned. One of the fields in the datagrid is a date field and they are all coming from SDE and Arc10.

What should be a date of: 2/18/2011 is displaying down in the grid as: 1297987200000. If i have the value of the date going to a label instead of to the datagrid i get 2/18/2011. I believe it is converting the date to milliseconds or something but i'm not sure how to go about formatting the column in the datagrid to display the date in the datagrid as 2/18/2011.

I have tried experimenting with the <MX:dateformatter> but haven't had any success is converting the column.

Has anybody else ran into this problem, or have suggestions?

Thanks...
Tags (2)
0 Kudos
3 Replies
DasaPaddock
Esri Regular Contributor
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jason,

   Here is an example of what Dasa is talking about. I do this in my Enhanced Search Widget so I had the label function already done.

   private function getDateLbl(item:Object,column:DataGridColumn):String
   {
    var dateMS:Number = Number(item[column.dataField]);
    var retVal:String = "";
    var rVal:String = item[column.dataField];
    if(rVal == null)
    {
     //do nothing
    }else{
     if (!isNaN(dateMS))
     {
      retVal = msToDate(dateMS, "MM/DD/YYYY");
     }
    }
    return retVal;
   }

   private function msToDate(ms:Number, dateFormat:String):String
   {
    var date:Date = new Date(ms);
    if (date.milliseconds == 999) // workaround for REST bug
    {
     date.milliseconds++;
    }
    
    if (dateFormat)
    {
     dateFormatter.formatString = dateFormat;
     var result:String = dateFormatter.format(date);
     if (result)
     {
      return result;
     }
     else
     {
      return dateFormatter.error;
     }
    }
    else
    {
     return date.toLocaleString();
    }
   }
0 Kudos
JasonNielsen
Regular Contributor
Thank you very much for the help Robert, and Dasa. I was able to get pass this datagrid issue and i can now concentrate on the rest of the application. 🙂
0 Kudos