<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: jqGrid dates formatted incorrectly using addRowData</title>
	<link>http://www.trirand.com/blog/?page_id=393/bugs/jqgrid-dates-formatted-incorrectly-using-addrowdata</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/bugs/jqgrid-dates-formatted-incorrectly-using-addrowdata/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>tony on jqGrid dates formatted incorrectly using addRowData</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/jqgrid-dates-formatted-incorrectly-using-addrowdata#p26768</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/jqgrid-dates-formatted-incorrectly-using-addrowdata#p26768</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Thanks. The fix is not the same, but there was a problem and fix it. See in GitHub</p>
</p>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Tue, 12 Jun 2012 09:26:37 +0300</pubDate>
        </item>
        <item>
        	<title>APWalker on jqGrid dates formatted incorrectly using addRowData</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/jqgrid-dates-formatted-incorrectly-using-addrowdata#p26721</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/jqgrid-dates-formatted-incorrectly-using-addrowdata#p26721</guid>
        	        	<description><![CDATA[<p>Hi,</p>
<p>There appears to be a problem with jqGrid&#8217;s date formatting when data is added using addRowData &#8211; dates are corrupted when they are formatted for display in the grid.</p>
<p>The problem can easily be seen by making a simple addition to the ok-soft-gmbh example found at&#160;<a href="http://www.ok-soft-gmbh.com/jqGrid/TimeFormat.htm" target="_blank">TimeFormat.htm</a>.&#160; After the line of code containing the call to &#39;gridResize&#39;, add the following two lines:</p>
</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $grid.jqGrid(&#39;addRowData&#39;, 13, { id: "13&#8243;,&#160; invdate: "2007-10-01T16:47&#8243;, invdate1: "2007-10-01T16:47&#8243;, name: "testXX",&#160;&#160; note: "note",&#160;&#160; amount: "200.00&#8243;, tax: "10.00&#8243;, closed: true,&#160; ship_via: "TN", total: "210.00&#8243; } );</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $grid.jqGrid(&#39;setGridParam&#39;,{ page: 1 }).trigger("reloadGrid");</p>
</p>
<p>Except for the ID and the name, the data being added here is identical to the 1<sup>st</sup> row of data in myData.&#160; However, when the grid is rendered after the &#8216;reloadGrid&#8217; call, the date and time displayed in the grid for the data added using addRowData does not match the date and time of the 1<sup>st</sup> row:</p>
</p>
<p>Date and time for 1<sup>st</sup> row:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 01.10.2007&#160;&#160;&#160;&#160;&#160;&#160;&#160; 16:47&#160;&#160;&#160;</p>
<p>Date and time for row added with &#8216;addRowData&#8217;:&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1.1.2001&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0:10</p>
<p>(To make the comparison easier remove all but the 1<sup>st</sup> row from myData in the original code; however, this is not necessary to reproduce the problem.)</p>
<p>I then modified the code to change all references from jqGrid &#8220;4.3.1&#8221; to &#8220;4.3.3&#8221; and found that the problem still exists in 4.3.3, but the date is corrupted to a different value:</p>
<p>Date and time for 1<sup>st</sup> row:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 01.10.2007&#160;&#160;&#160;&#160;&#160;&#160;&#160; 16:47 &#160;&#160;</p>
<p>Date and time for row added with &#8216;addRowData&#8217;: &#160; &#160; &#160; &#160; &#160; &#160; 30.03.2007&#160;&#160;&#160;&#160;&#160;&#160;&#160; 15:10</p>
<p>The problem appears to be due to the jqGrid code calling $.unformat.date that&#8217;s defined on or about line 5327 of the 4.3.3 version of jquery.jqGrid.src.js.&#160; unformat.date is not called when the original data is loaded when the grid is created, only when data is added using addRowData.</p>
<p>A workaround fix that I&#8217;ve made to the $.unformat.date function in my local copy of &#160;jquery.jqGrid.src.js&#160;is to add the code contained within the &#8220;apw change&#8221; comments below:</p>
<p>&#160; &#160; &#160; &#160; &#160; &#160; $.unformat.date = function (cellval, opts) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var op = $.jgrid.formatter.date &#124;&#124; {};</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(!$.fmatter.isUndefined(opts.formatoptions)) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; op = $.extend({},op,opts.formatoptions);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(!$.fmatter.isEmpty(cellval)) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // start apw change</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (Object.prototype.toString.call(cellval) === "[object Date]" ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return cellval;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // end apw change</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return&#160; $.fmatter.util.DateFormat(op.newformat,cellval,op.srcformat,op);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return $.fn.fmatter.defaultFormat(cellval, opts);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; };</p>
</p>
<p>This change skips the unformat operation if the date to be formatted already is a Date object. In fact, this might be a useful change to include even when the underlying problem of parsing the in-bound date value is fixed, because there&#8217;s no need to perform this &#8220;unformat&#8221; operation if the object is already a date.&#160;</p>
<p>For this change to work with the <a href="http://www.ok-soft-gmbh.com/jqGrid/TimeFormat.htm" target="_blank">TimeFormat.htm</a>&#160;example cited above, the two date strings in the data added by addRowData need to be changed to Date objects. &#160;</p></p>
]]></description>
        	        	<pubDate>Sun, 03 Jun 2012 17:37:43 +0300</pubDate>
        </item>
</channel>
</rss>