Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
jqGrid dates formatted incorrectly using addRowData
03/06/2012
17:37
Avatar
APWalker
Maryland, USA
New Member
Members
Forum Posts: 1
Member Since:
03/06/2012
sp_UserOfflineSmall Offline

Hi,

There appears to be a problem with jqGrid’s date formatting when data is added using addRowData – dates are corrupted when they are formatted for display in the grid.

The problem can easily be seen by making a simple addition to the ok-soft-gmbh example found at TimeFormat.htm.  After the line of code containing the call to 'gridResize', add the following two lines:

            $grid.jqGrid('addRowData', 13, { id: "13″,  invdate: "2007-10-01T16:47″, invdate1: "2007-10-01T16:47″, name: "testXX",   note: "note",   amount: "200.00″, tax: "10.00″, closed: true,  ship_via: "TN", total: "210.00″ } );

            $grid.jqGrid('setGridParam',{ page: 1 }).trigger("reloadGrid");

Except for the ID and the name, the data being added here is identical to the 1st row of data in myData.  However, when the grid is rendered after the ‘reloadGrid’ call, the date and time displayed in the grid for the data added using addRowData does not match the date and time of the 1st row:

Date and time for 1st row:                                                01.10.2007        16:47   

Date and time for row added with ‘addRowData’:               1.1.2001            0:10

(To make the comparison easier remove all but the 1st row from myData in the original code; however, this is not necessary to reproduce the problem.)

I then modified the code to change all references from jqGrid “4.3.1” to “4.3.3” and found that the problem still exists in 4.3.3, but the date is corrupted to a different value:

Date and time for 1st row:                                                01.10.2007        16:47   

Date and time for row added with ‘addRowData’:             30.03.2007        15:10

The problem appears to be due to the jqGrid code calling $.unformat.date that’s defined on or about line 5327 of the 4.3.3 version of jquery.jqGrid.src.js.  unformat.date is not called when the original data is loaded when the grid is created, only when data is added using addRowData.

A workaround fix that I’ve made to the $.unformat.date function in my local copy of  jquery.jqGrid.src.js is to add the code contained within the “apw change” comments below:

            $.unformat.date = function (cellval, opts) {

                        var op = $.jgrid.formatter.date || {};

                        if(!$.fmatter.isUndefined(opts.formatoptions)) {

                                    op = $.extend({},op,opts.formatoptions);

                        }                      

                        if(!$.fmatter.isEmpty(cellval)) {

                                    // start apw change

                                    if (Object.prototype.toString.call(cellval) === "[object Date]" ) {

                                                return cellval;

                                    }

                                    // end apw change

                                    return  $.fmatter.util.DateFormat(op.newformat,cellval,op.srcformat,op);

                        } else {

                                    return $.fn.fmatter.defaultFormat(cellval, opts);

                        }

            };

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’s no need to perform this “unformat” operation if the object is already a date. 

For this change to work with the TimeFormat.htm example cited above, the two date strings in the data added by addRowData need to be changed to Date objects.  

12/06/2012
09:26
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Thanks. The fix is not the same, but there was a problem and fix it. See in GitHub

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
44 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information