-
20 Oct 2010 10:29 PM #1
Configurable submitFormat on date fields in JsonStore
Configurable submitFormat on date fields in JsonStore
I use an editorgrid to edit elements from a JsonStore. The JsonStore uses a HttpProxy to update the backend database.
My problem is that the backend API expects fromTs and toTs to be unix timestamps, but when a record is updated, the resulting http post contains a date formatted like this: Wed Oct 20 00:00:00 UTC+0200 2010
I've searched the API documentation for a parameter to control the post format, but I've not been able to find anything. Is there a simple way to do this?
The editorgrid is configured like this:Code:myJsonStore = new Ext.data.JsonStore({ autoLoad: true, autoSave: true, proxy: new Ext.data.HttpProxy({ api: { create: '/create/', read: '/read/', update: '/update/', destroy:'/destroy/' } }), writer: new Ext.data.JsonWriter({ encode: true, writeAllFields: true }), idProperty: 'id', fields: [ {name: 'id', type: 'int'}, {name: 'fromTs', type: 'date', dateFormat:'timestamp'}, {name: 'toTs', type: 'date', dateFormat:'timestamp'} ] });
Also posted on StackOverflow: http://stackoverflow.com/questions/3...unix-timestampCode:{ xtype: 'editorgrid', clicksToEdit: 1, columns: [ {header: "Id", dataIndex: 'id', editable: false}, {header: "From", dataIndex: 'fromTs', editor: new Ext.form.DateField({format: 'd.m.Y', startDay: 1}), xtype: 'datecolumn', format: 'd.m.Y'}, {header: "To", dataIndex: 'toTs', editor: new Ext.form.DateField({format: 'd.m.Y', startDay: 1}), xtype: 'datecolumn', format: 'd.m.Y'} ], store: myJsonStore }
-
18 Mar 2011 4:52 AM #2
Manipulate the post params in the HttpProxy event beforewrite
Manipulate the post params in the HttpProxy event beforewrite
I know this case is old, but I found a solution to this problem that I never came around to post here.
I added a listener to the proxy's beforewrite event, and manipulated the post params there
Code:proxy: new Ext.data.HttpProxy({ api: { create: '/create/', read: '/read/', update: '/update/', destroy:'/destroy/' }, listeners: { beforewrite: function(proxy, action, record, params) { var fromTs = record.data.fromTs; var toTs = record.data.toTs; if(record.data.fromTs) record.data.fromTs = fromTs.format('U'); if(record.data.toTs) record.data.toTs = toTs.format('U'); // Update record to be sent // root = store.reader.root params.root = Ext.util.JSON.encode(record.data); // Restore record record.data.fromTs = fromTs; record.data.toTs = toTs; } } })Last edited by Springvar; 18 Mar 2011 at 4:55 AM. Reason: Preview equals post in this forum... I still need to edit
Similar Threads
-
XDateField with configurable submitFormat
By jsakalos in forum Ext 2.x: User Extensions and PluginsReplies: 76Last Post: 30 Nov 2011, 8:42 AM -
DateField: displayFormat VS submitFormat
By tobiu in forum Ext 3.x: Help & DiscussionReplies: 6Last Post: 11 Feb 2010, 9:35 AM -
XTimeField with configurable submitFormat
By jsakalos in forum Ext 2.x: User Extensions and PluginsReplies: 2Last Post: 6 Jul 2009, 5:50 AM -
[2.1][DUP][FIXED] DateField & jsonstore with fields with type: 'date' and dateFormat
By cvieira in forum Ext 2.x: BugsReplies: 5Last Post: 20 May 2008, 6:13 PM


Reply With Quote