VJAI
VJAI

Reputation: 32768

Reg. date format issue in json with jqgrid

I'm using jqgrid and have columns that display date but from the server the date comes in json format as below,

"CommentedDate": "\/Date(1304324941000+0530)\/"

How I can display the date correctly in MM/dd/yyyy format?

Vijaya Anand

Upvotes: 2

Views: 7323

Answers (2)

chandy4eva
chandy4eva

Reputation: 11

I have resolved the NaN/NaN/NaN issue for date-field by manually altering the jquery.jqgrid.src.js (4.5.2). In my case, the json response would return date in an 'ISO1860Long'. It used to work till the 4.1.2 jqgrid version

Search for "parseDate" function; goto the line after :

if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
if(date && date != null) {

and add the below if check :

if(date.constructor === Number) {
  if(String(format).toLowerCase() == "u") {
    date = date*1000;
  }
  timestamp = new Date(date);
} else

before the existing :

if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {

you can translate the changes to jquery.jqgrid.min.js yourself IF needed

Upvotes: 0

Oleg
Oleg

Reputation: 221997

If you use predefined formatter 'date' and jqGrid 4.0 it should work automatically. Try for example with the following properties for the column having the date:

formatter:'date', formatoptions: {newformat:'m/d/Y'}

Upvotes: 10

Related Questions