jqgrid date not displaying correctly

2.7k Views Asked by At

Using JQGrid 4.6.0

SQL Server using a date field to hold the meeting date. NO TIME.

enter image description here

Using this code block (note the formatter) - with the value of datetime

enter image description here

This is the resulting output

enter image description here

The date field shows the correct date, in the correct format - EXCEPT the timestamp is being displayed.

Now using date only in the formatter

enter image description here

This is the output i am receiving

enter image description here

Two things to look at - one, the timestamp is gone - yeah! BUT the dates are WAAAYYY off.

What i am looking for is to display the date as it comes from the date field in the database, using the customer accepted format of (m/d/Y - 12/31/2014)

Am i missing something?

2

There are 2 best solutions below

0
On BEST ANSWER

A bit late, but can be useful for future searchers.

To display correct date:

  • On server - Return dateTime in correct format, json example:

    "dateTime":"2016-01-19T19:12:42.93"

  • On Client - Use this column configuration

    sorttype: 'date', formatter: 'date', formatoptions: { srcformat:'ISO8601Long', newformat: 'm.d.Y'}

This configurations allows to display correct date and this column will have correct sorting.

Note: jqGrid dosn't have datetime formater, see this answer

4
On

you can try it like this.

sorttype: 'date', formatter: 'date', formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'm/d/Y', defaultValue: null}

If this does not solves your issue there can be issue parsing with it. Please try to convert it to string format before sending it to jqgrid.