1

Extjs grid Model has,

{
    name: "ORDERDATE",
    type: 'date',
    dateFormat: 'MS'
}

and I tried sync store that has above model,

then the date posted format is like this (Json Type),

ORDERDATE "\/Date(1346212800000)\/"

and I guess because of this format,

in Asp.net(C#) couldn't get that value using DateTime? variable.

I tried to receive that data using DateTime? ORDERDATE, but it has Null value all the time.

So, I want to try to change the date post format as 'm/d/y', but I don't know how to do this,

anybody know, please advice me.

Thank you.

Izhaki
  • 23,372
  • 9
  • 69
  • 107
Expert wanna be
  • 10,218
  • 26
  • 105
  • 158

2 Answers2

2

I was having the same problem. Using the convert config (docs) on my date field worked for me.

So my model has something like:

fields: [
    { name: 'SomeField', type: 'string'} 
    ...
    , { name: 'TimeStamp',
      type: 'date',
      //dateFormat: 'MS',          
      convert: function (value, record) {
        //Convert date type that .NET can bind to DateTime
        var date = new Date(parseInt(value.substr(6)));
        return Ext.Date.format(date, 'l, F d, Y g:i:s A'); //Full Date Time
      }
    }
]

I believe in the future we can use the serialize config (docs) which converts the field before sending model to server. Sounds like it is only working in 4.1.2 and beyond.

In that case, I believe this would work:

fields: [
    { name: 'SomeField', type: 'string'} 
    ...
    , { name: 'TimeStamp',
      type: 'date',
      dateFormat: 'MS',          
      serialize: function (value, record) {
        //Convert date type that .NET can bind to DateTime
        var date = new Date(parseInt(value.substr(6)));
        return Ext.Date.format(date, 'l, F d, Y g:i:s A'); //Full Date Time
      }
    }
]
Justin
  • 1,310
  • 3
  • 18
  • 29
1

To change the date format you can use this chart from the docs.

So dateFormat: 'm/d/y' should do the trick for you.

Although I would wait to see if any asp.net wizard pops in to help cause it looks odd to me that a microsoft format is not supported by its own Asp.net.

Community
  • 1
  • 1
Izhaki
  • 23,372
  • 9
  • 69
  • 107
  • Thank you for your answer, Is there a way make decode 'Microsoft AJAX serialized dates' ,when sync store? because the dateFormat should be 'MS' and when sync store, I want to post the date type as 'm/d/y'. – Expert wanna be Aug 17 '12 at 12:32
  • OK, what do you get in the request when `dateFormat:'ms'` and what do you get with `dateFormate:'m/d/y'`? – Izhaki Aug 17 '12 at 12:34
  • if using dateFormat:'m/d/y', it does not display anything. the server send date data as "ADATE":"\/Date(1345003200000)\/" – Expert wanna be Aug 17 '12 at 12:46
  • Ok, just to clarify, is it the data the server return to the client you cannot read, or the data the client sends the server the server does not understand? – Izhaki Aug 17 '12 at 12:58
  • For me 'sync' with a store is for update/create/destroy, where 'load' is for read operations. – Izhaki Aug 17 '12 at 12:58
  • And so if the server returns `"ADATE":"\/Date(1345003200000)\/"`, other than the server returns `ADATE` and your model is `ORDERDATE`, a `dateFormat:"MS"` won't read it, is this the problem? – Izhaki Aug 17 '12 at 12:59
  • Oh ADATE and ORDERDATE is not a problem. I can read the date data using dateFormat:'MS' because server send Microsoft AJAX serialized date type. But I want to change the dateFormat for sending to server when I sync my store. – Expert wanna be Aug 17 '12 at 13:06
  • OK, so if I understand correctly loading data from the server works with `dateFormat:"MS"`, but not sending data to the server? It appears from your question that the JSON sent is in the right format, am I correct? – Izhaki Aug 17 '12 at 13:10
  • It's sending data to server also, but the type is 'Microsoft AJAX serialized dates', it is same type what Extjs received from server. but my asp.net couldn't read the type of date. So I want to try to change date format for sending to server when sync store. – Expert wanna be Aug 17 '12 at 13:16
  • I'd have a look at [this thread](http://stackoverflow.com/questions/206384/how-to-format-a-json-date), I believe your should get the server side to work. Is your intention to get in MS, but send using a different format? – Izhaki Aug 17 '12 at 13:27
  • Thank you for your help, I will look for the server side work. – Expert wanna be Aug 17 '12 at 14:11