PDA

View Full Version : problem with date binding



hieu79vn
3 Jul 2012, 8:23 AM
Hi
I have a datefield and I tried to do like this to make the datefield show my data
xtype: 'datefield',
fieldLabel: 'Due date',
name: 'thread_end_date',
value: '26 Mar 2012',
columnWidth: 0.25,
format: 'd M Y'
but it doesn't show the value even i think the format is correct

Do you have any idea?
Thanks

friend
3 Jul 2012, 9:26 AM
Take a look at the API docs for Ext.form.field.Date (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.form.field.Date). Example code is provided for setting the date properly.

hieu79vn
3 Jul 2012, 11:21 PM
Thank you friend
But if we look at the Date format example in the article you sent to me, it doesn't work neither.
Do you have any idea?

friend
5 Jul 2012, 4:33 AM
This works for me:



Ext.create('Ext.window.Window', {
bodyPadding: 5,
height: 100,
layout: 'anchor',
title: 'Date Test',
width: 176,
items: [{
xtype: 'datefield',
anchor: '100%',
fieldLabel: 'A Date',
format: 'd M Y',
labelWidth: 50,
value: '01 MAR 2012'
}]
}).show();

hieu79vn
5 Jul 2012, 11:36 PM
Thank you friend.
I know my problem. Because I my date is format in json like this Date010220012UC+002 ...., so the datefield doesn't understand. Do you know how to format this kind of date to dMY?

Thank you

redraid
6 Jul 2012, 12:52 AM
If you use models use convert (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Field-cfg-convert) function in field config:


function convertDate(value) {
return value;// convert date from you format
}

Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'date', type:'date', convert: convertDate}
]
});

or dateFormat cfg (format string see Ext.Date.parse (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Date-method-parse)):


Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'date', type:'date', dateFormat: ''}
]
});