PDA

View Full Version : Problem with rendering date in correct format



hudi1
3 Jun 2013, 7:07 AM
Hi,

in my form I have field:


{
xtype : 'displayfield',
// type : 'date',
renderer : function(value, displayField) {
console.log(value + "aaaaaaaaaaaaaaa")
return Ext.util.Format.dateRenderer('d.m.Y')(value)
},
itemId : 'dateOfBirth',
fieldLabel : 'Date of Birth'
}

when value is: Thu Sep 28 1967 00:00:00 GMT+0200 (CEST)aaaaaaaaaaaaaaa date is displayed in right format but when value is: 28.09.1967aaaaaaaaaaaaaaa then displayed value is: NaN.NaN.0NaN
why it isnt working with second value ? I need to parse both value and displayed it in right format

jasewell
3 Jun 2013, 1:20 PM
The function created by dateRendererer expects a JavaScript Date object as input. That's why your first one is working. The second one looks like it's already in your desired format, so perhaps you could test the type of your input and then return the appropriate one?

renderer : function(value) {
return Ext.isString(value) ? value : Ext.Date.format(value, 'd.m.Y');
}

Of course, this assumes that, when you're getting strings, they're in the right format already. You might also investigate why sometimes you're getting Date objects and sometimes strings.