Serendipity
Serendipity

Reputation: 1037

JQGrid Date Formatting Issue

Recently we came across an issue where dates were being represented incorrectly by jQGrid. There were other dates in the table that seemed to work perfectly fine. However, certain dates were failing.

I have created a fiddle here for a demo of the problem. Note that the input date value is "10/24/2015" with format for jQGrid as "m/d/Y". The output in the table however is "06/06/2017".

The column definition for the date column looks like this: (fiddle is forked from one written by Oleg himself).

    {
        name: 'invdate', index: 'invdate', search: false, editable: true, align: "left", width: 75, 
        formatter: function (cellvalue, options, rowObject) {
            return cellvalue === null ? "N/A" : $.fn.fmatter.call(this, "date", cellvalue, options, rowObject);
        }, formatoptions: { newformat: "m/d/Y" }
    }

I am still analyzing the source code to understand how jQgrid formats dates. Any help would be appreciated.

Upvotes: 0

Views: 97

Answers (1)

Jai
Jai

Reputation: 74738

I guess you need to have srcFormat in the formatoptions too:

formatoptions: {
    srcformat: "m/d/Y", //<----add this too
    newformat: "m/d/Y"
}

Fiddle

Upvotes: 1

Related Questions