PDA

View Full Version : Store date format submit



bkraut
29 Dec 2009, 2:43 PM
Hi,

whenever I use date within a grid and try to update a value I get an error when submitting, as the format is not as set on grid store.

My data format is allways in format '2009-12-30T00:00:00'

Here an example:

Method for updating data:



updateRecord: function(record) {
Ext.Ajax.request({
url: 'Controller/Core/persistence.crud.Save',
params: Ext.apply(
record.data, {
className: this.className,
parent: this.params.id
}),
timeout: 10000,
success: function(response,recordData) {
this.store.reload();
},
failure : function(response) {
Ext.MessageBox.alert ('Error', Ext.decode(response.responseText).message);
},
scope: this
});
}


and grid store fields and column definitions:



fields: [
{name: 'id', type: 'int', allowBlank: false},
{name: 'value', type: 'float', allowBlank: false},
{name: 'quantity', type: 'float', allowBlank: false},
{name: 'price', type: 'float', allowBlank: false},
{name: 'discount', type: 'float', allowBlank: false},
{name: 'note', type: 'string'},
{name: 'supplymentDate', type: 'date', dateFormat: 'Y-m-d'},
{name: 'total', type: 'float', allowBlank: false},
{name: 'optional', type: 'boolean'},
{name: 'itemDescription', type: 'string', allowBlank: false},
{name: 'costDriver', type: 'int'},
{name: 'item', type: 'int', allowBlank: false},
{name: 'unitOfMeasure', type: 'int', allowBlank: false},
{name: 'vatClass', type: 'int', allowBlank: false}
],






var columns = [
new Ext.grid.RowNumberer(),
{header: "Item", width: 120, dataIndex: 'item', renderer: new Ext.ux.ComboRenderer(itemChooser), editor: itemChooser},
{header: "Description", width: 180, sortable: true, dataIndex: 'itemDescription', editor: itemDescriptionEditor},
{header: "Unit", width: 40, sortable: true, dataIndex: 'unitOfMeasure', renderer: new Ext.ux.ComboRenderer(unitOfMeasureChooser), editor: unitOfMeasureChooser},
{header: "Quantity", width: 40, sortable: true, dataIndex: 'quantity', editor: quantityEditor},
{header: "Price", width: 80, sortable: true, dataIndex: 'price', editor: priceEditor},
{header: "Discount", width: 40, sortable: true, dataIndex: 'discount', editor: discountEditor},
{header: "Vat Class", width: 40, sortable: true, dataIndex: 'vatClass', renderer: new Ext.ux.ComboRenderer(vatClassChooser), editor: vatClassChooser},
{header: "Value", width: 80, sortable: true, dataIndex: 'value', editor: valueEditor},
{header: "Total", width: 80, sortable: true, dataIndex: 'total', editor: totalEditor},
{header: "Note", width: 300, sortable: true, dataIndex: 'note', editor: noteEditor},
{header: "Cost Driver", width: 120, sortable: true, dataIndex: 'costDriver', renderer: new Ext.ux.ComboRenderer(costDriverChooser), editor: costDriverChooser},
{header: "Supplyment Date", width: 75, sortable: true, dataIndex: 'supplymentDate', renderer: new Ext.ux.DateRenderer('d.m.Y'), editor: supplymentDateEditor},
optionalColumn
];


I'm aware of Saki solution when using XDateField, but is there any other way how can I send a date to server in format that I'd define?

Maybe some override of a DateField class?

Condor
30 Dec 2009, 2:08 AM
This has nothing to do with DateField. You are sending the record data unmodified to the server (which includes a Date instance).

Either convert the Date to a String before you send it, e.g.

params: Ext.applyIf({
supplymentDate: record.get('supplymentDate').dateFormat('Y-m-d'),
className: this.className,
parent: this.params.id
}, record.data),
(Note: I changed the apply to an applyIf with reversed parameters, because otherwise you are modifying the record!)

Or change the default JSON Date encoding:

Ext.util.JSON.encodeDate = function(d){
return d.dateFormat('Y-m-d');
}
(Warning: this affects ALL JSON encoded Date instances!)

bkraut
30 Dec 2009, 3:10 AM
Condor - thank you very much. I have a working solution now. I wasn't aware of this functionality.

bhunnicutt
13 Mar 2012, 10:25 AM
This thread helped me! Keep in mind I'm new to Ext and working in Ext JS 4.0.7. I'm using the following code:


Ext.JSON.encodeDate = function(date){
if (Ext.isEmpty(date)) {
return "";
} else {
return "\"" + Ext.Date.format(date, "m/d/Y H:i") + "\"";
}
};