PDA

View Full Version : Store date type field save format problem



bkraut
26 Aug 2011, 6:08 AM
Hi,

Whenever I save a store from grid the date field format is like '2011-08-26T00:00:00'. I'd like to format sent date like '26.08.2011 00:00:00'.

Record definition:



var DailyAllowance = Ext.data.Record.create([
{ name: 'uuid' },
{ name: 'country', type: 'string', allowBlank: false },
{ name: 'currency', type: 'string', allowBlank: false },
{ name: 'dailyAllowance', type: 'string', allowBlank: false },
{ name: 'dailyAllowancePrice', type: 'double', allowBlank: false },
{ name: 'validFromDate', type: 'date', dateFormat: 'Y-m-d', allowBlank: false}
]);


Here is my store code:



Ext.namespace("Ext.ux");

Ext.ux.DailyAllowanceStore = Ext.extend(Ext.data.Store, {

// ***********************************************************************************
// ***********************************************************************************
// Constructor
// ***********************************************************************************
// ***********************************************************************************

constructor: function(params) {

var config = {
storeId: 'sDailyAllowance',
proxy: new Ext.data.HttpProxy({
restful: true,
url: 'hrm/travelclaim/sets/dailyallowance'
}),
reader: new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'uuid',
root: 'data',
messageProperty: 'message'
},
DailyAllowance),
writer: new Ext.SpringWriter(),
autoSave: false
};
Ext.apply(config, params);
Ext.apply(this, Ext.apply(this.initialConfig, config));
Ext.ux.DailyAllowanceStore.superclass.constructor.call(this, config);
}

});

//***********************************************************************************
//***********************************************************************************
//Registering xtype
//***********************************************************************************
//***********************************************************************************

Ext.reg('DailyAllowanceStore', Ext.ux.DailyAllowanceStore);


And here is my grid column code:


{ xtype: 'datecolumn', header: "Valid from date", dataIndex: "validFromDate", filterable: true, sortable: true, editor: new Ext.form.DateField({ allowBlank: false }) }


How can I set date format that the store is sending?

bkraut
28 Aug 2011, 12:51 PM
I used default examples of extjs 3.3 and modified edit-grid.js.

My override:



var store = new Ext.data.Store({
// destroy the store if the grid is destroyed
autoDestroy: true,

// load remote data using HTTP
url: 'plants.xml',
restful: true,

// specify a XmlReader (coincides with the XML format of the returned data)
reader: new Ext.data.XmlReader({
// records will have a 'plant' tag
record: 'plant',
// use an Array of field definition objects to implicitly create a Record constructor
fields: [
// the 'name' below matches the tag name to read, except 'availDate'
// which is mapped to the tag 'availability'
{name: 'common', type: 'string'},
{name: 'botanical', type: 'string'},
{name: 'light'},
{name: 'price', type: 'float'},
// dates can be automatically converted by specifying dateFormat
{name: 'availDate', mapping: 'availability', type: 'date', dateFormat: 'm/d/Y'},
{name: 'indoor', type: 'bool'}
]
}),
writer: new Ext.data.JsonWriter({
encode: false,
writeAllFields: true,
listful: true,
render: function(params, baseParams, data) {
params.jsonData = data;
}
}),

sortInfo: {field:'common', direction:'ASC'}
});


The date is encoded like I descirbed above - "2006-04-27T00:00:00". How can I format a submited date in json?

JSON sent to the server:



JSON


availability
"2006-04-27T00:00:00"

botanical
"Monarda didyma"

common
"Bergamot"

indoor
true

light
"Mostly Shady"

price
7.16

Novalis
15 Sep 2011, 11:28 PM
same question for me! any suggestions?
explanation from condor + suggestion:
http://www.sencha.com/forum/showthread.php?114690-Problem-with-Store-save-and-date-format