As most of you know, the DataGrid provides an easy way for you to format your dates in a column by specifying a simple format property and a formatString variable:
All you have to do is :
col.format = flexiciousNmsp.FlexDataGridColumn.FORMAT_DATE;
col.formatterDateFormatString = "YOUR_FORMAT";
Now the actual implementation of the formatting depends on the underlying library. For the jQuery version of the product, we use the jquery UI's datepicker format method internally:
return $.datepicker.formatDate(dateFormat,date);
But what if you want to use a different formatting mechanism? For example, moment.js is currently the most popular date formatting library, and has a different format string structure as compared to jQuery UI. As is the case for an existing customer of ours who we are assisting to move from Flex to HTML, what if your backend sent formatStrings that were not consistent with jQuery UI (or your backend has to support both Flex and HTML)? Well, never fear, all you have to do is to include moment.js and add this little gem:
//hijack calls to jquery into moment, which plays better with Flex - like
//format strings.
flexiciousNmsp.DateFormatter.prototype.format=function(value ){
if(value instanceof Date)
return moment(value).format(this.formatString)
else
return "";
}