PDA

View Full Version : WCF/Json Dates ..



zz9pa
28 Sep 2012, 2:14 AM
I'm using a slight modification on Maicon Schelters OData proxy thats around here somewhere and I've managed to get some data out of my C# project and back into an Ext.js grid - I needed to add something like :

..
{ name:'StartDate', type:'date', dateFormat:'MS'},
..

To get the dates to work..

Then in my grid - I define the column :

{
dataIndex:'StartDate',
header: 'Start Date',
format:'Y-m-d H:i:s', editor: {xtype:'datefield',format:'Y-m-d H:i:s'},
xtype:'datecolumn'
} ,


Now - when I edit any data (any data - even when I dont change data in this field) and try to sync it back - I get an extra \ on either side of my date..

According to fiddler2 - when the date comes across from the server - its like this :

"StartDate": "\/Date(695036587540)\/"

When I send it back - its :

"StartDate":"\\/Date(695036587540)\\/"

Any ideas on whats adding it in - how I can remove it ?
(it *seems* like it might be 'setOptions in ext-4.1.1/ext-all-debug.js - around line 37807)

(the .net service is complaining "String was not recognized as a valid DateTime.")


Any help would be much appreciated!

scottmartin
1 Oct 2012, 6:21 AM
I would use a real debugger like DevTools (Chrome) or FireBug and set a breakpoint and find out where this is happening. Perhaps proxy you mentioned? Do you want the Date() included?

Scott.

zz9pa
1 Oct 2012, 7:58 AM
I think I've got fairly close now...


I added a function :

function fromMs(value) {
return Ext.Date.parse(value,'MS');
}


and I call that :

{ name:'StartDate', type:'date',convert: fromMs},
which *seems* to be working atm



(I use this in a lot of places - so putting the conversion in a separate function makes sense for me...)