PDA

View Full Version : ExtJS: store format and Date field format "auto-conversion" problem



olivierpons
17 Sep 2012, 12:09 PM
Hi,

I'm defining my model like this:


Ext.define('Gestion.Horaire', { extend: 'Ext.data.Model',
fields: [
{
name: 'date_end',
type: 'date',
dateFormat: 'Y-m-d H:i:s'
},
...


When the data is read in JSON format, it's ok: values are 'Y-m-d H:i:s'.

Now I want to display them differently in a DateTime component:


Ext.define('Gestion.horaires.form.Panel', { ...blabla...
initComponent: function(){



Ext.apply(this,
items: [{
xtype: 'form',
... blabla ...
items: [{
fieldLabel: 'Date fin ',
name: 'date_end',


xtype: 'datefield',
format: 'd/m/Y',
allowBlank: false
}
... blabla ...

And when I try in a button event:


var form = this.gsForm.getForm();
if (form.isValid()) {
this.store.insert(0, form.getValues());
}

The values I read from form.getValues() are in the format 'd/m/Y' and thus when I try to insert, as I can read in the code, in the "createModel" function, it calls 'set()' which calls "Ext.apply.DATE.convert" and, of course, the format 'd/m/Y' isn't recognized, thus Ext.apply.DATE.convert returns null.

What can I do to convert the date before it's "converted"? Or maybe I'm missing a property I should set to make all of that work?

olivierpons
17 Sep 2012, 12:17 PM
I found it, it was the property


submitFormat: 'Y-m-d H:i:s',

Thus the component is declared like this:


{ fieldLabel: 'Date start ',
name: 'date_debut',
xtype: 'datefield',
format: 'd/m/Y',
submitFormat: 'Y-m-d H:i:s',
allowBlank: false
}

natiishyn
30 Dec 2013, 6:48 AM
Hello guys,From server I receive such data:

expirationDate : "2014-08-27T22:00:00.000+0000"
and in MVC ExtJS 4 in Model I have this:

fields: [
...
{name: "expirationDate", type: Ext.data.Types.DATE, dateFormat:"yyyy-MM-dd'T'HH:mm:ss.SSSz"},
...
But the main problem is that dateFormat. Which should I choose for my date sample?

mgolka
24 Jan 2014, 8:39 AM
dateFormat: 'c' should do

Regards

natiishyn
27 Jan 2014, 3:04 AM
Yes, it worked. Thank you