Forum
00:14
10/08/2009
Hello Tony!
From time to time somebody ask why the date format like "/Date(1285128000000)/" are not suported by jqGrid. Today I answerd one more time on the question on the stackoverflow.
Why not make a small modification of the jquery.fmatter.js to support this? It seems to me that one need to add only two lines of code for example atfter the line 144:
if(date.constructor === Number) {
timestamp = new Date(date);
} else if (typedef date === "string" && /^\/Date\(\d+\)\/$/.test(date)) {
// Microsoft serialization format for date: "/Date()/"
timestamp = new Date(parseInt(date.substr(6,date.length-8),10));
} else if(date.constructor === Date) {
timestamp = date;
Bold text are the suggested lines. What do you think about this?
Best regards
Oleg
14:55
10/08/2009
Hello Tony!
I made some more tests and improved my suggestion to have full support of the DateTime .NET format used by Microsoft for serialization in WFC, ASP.NET MVC or ASMX Web Services (so in all kinds of JSON DateTime serialization). The serialized format of DateTime class is described in the section "DateTime Wire Format" of http://msdn.microsoft.com/en-u.....12170.aspx.
The corresponding changes in the jquery.fmatter.js can be following. The lines 142-146
timestamp = new Date(date);
} else if(date.constructor === Date) {
timestamp = date;
} else {
should be replaced to the following
// the definition of msDateRegExp can be changed to static
var msMatch = date.match(msDateRegExp);
if(date.constructor === Number) {
timestamp = new Date(date);
} else if(date.constructor === Date) {
timestamp = date;
} else if (msMatch !== null) {
// The serialized format of DateTime class is described in the section
// "DateTime Wire Format" of http://msdn.microsoft.com/en-us/library/bb412170.aspx
// The date can be sent in one of the following form
// 1) UTC time will be sent as "/Date(1291813200000)/" or "/Date(-167443200000)/"
// (created for example like new DateTime(1964,09,11,0,0,0,0,DateTimeKind.Utc))
// 2) the local time from a time zone as "/Date(1291813200000+0100)/"
// or "/Date(-167443200000+0000)/"
//
// msMatch will be array with the following contain
// msMatch[0] - the string itself
// msMatch[1] - the number of milliseconds since midnight, January 1, 1970
// (may be negative to represent earlier times)
// msMatch[2] - '' or '-'. '-' if the time is before January 1, 1970
// msMatch[3] - '' or string like '+0100'
// msMatch[4] - '' or '+' if d[3]==='+0100'
// msMatch[5] - '' or '01' if d[3]==='+0100'
// msMatch[6] - '' or '00' if d[3]==='+0100'
timestamp = new Date(parseInt(msMatch[1], 10));
if (msMatch[3]) { // if timezone defined so the time is local and not Utc
var offset = Number(msMatch[5]) * 60 + Number(msMatch[6]);
offset *= ((msMatch[4] == '-') ? 1 : -1);
offset -= timestamp.getTimezoneOffset();
timestamp.setTime(Number(Number(timestamp) + (offset * 60 * 1000)));
}
} else {
The changes will be useful for all .NET developers. How you can see I use in the code RegExp matching, so I can really sure that the new piece of code will be executed only if the input is exactly in the correct "DateTime Wire Format" used Microsoft.
Best regards
Oleg
20:04
19/12/2010
09:15
04/01/2011
Hi Tony/Oleg,
jqGrid 3.8.1 is not working with the .Net DateTime for me. I think your line:
var msDateRegExp = new RegExp("^/Date\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\)/$");
should be:
var msDateRegExp = new RegExp("^/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)/$");
Note the extra escape characters - let me know what you think.
Regards,
Scott
14:33
10/08/2009
Sorry Scott,
but if you will read carefully the current thread, .NET DateTime format are supported starting with jqGrid 3.8.2 and not exist in jqGrid 3.8.1 which you use. Moreover in the code which I suggested and which is included in jqGrid 3.8.2 the msDateRegExp is already defined as
So it seems to me you should just use jqGrid 3.8.2.
Best regards
Oleg
21:28
04/01/2011
Hi Oleg
My apologies - a late night.
I am using jqGrid 3.8.2 and it is not working with a .Net DateTime. I get NaN/NaN/NaN.
When I posted the reg expression I did not notice that the forum was trimming a "".
I feel it should be - note the double "\" before the the "(":
var msDateRegExp = new RegExp("^/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)/$")
Thanks,
Scott
23:39
10/08/2009
Thank you very much Scott!
It is very hard to here, but the forum software has really hard and evil bug. I tested carefully my code before past it here. Of cause I didn't verify the code character per character after the pasting. Not I see that from the original RegEx
"^\\/Date\\\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\\\)\\\/$"
4 characters (4 backslashes) was cut and we have the text
"^\/Date\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\)\/$"
in the code of jqGrid 3.8.2. Please try one more time with the RegEx
"^\\/Date\\\\((([-+])?[0-9]+)(([-+])([0-9]{2})([0-9]{2}))?\\\\)\\\/$".
I don't verified other parts of the code. I'm really frustrated. Moreover curently I have less free time as before.
It all will works OK.
I hope Tony will read the post and fix the code of jqGrid. If he write no comments in the next 7 days I'll post a new bug report.
Best regards and thanks one more time
Oleg
14:25
Moderators
30/10/2007
Hello,
Will be fixed. Thanks.
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.
16:16
11/01/2011
Hi all !
I'm using jqGrid 3.8.2 to show data coming from a ASP.NET web service.
As far as I understood jqGrid natively understands MS DateTime Wire Format by default (since 3.8.2) and this is good, but it renders something like:
NaN/NaN/NaN
Probably I have to set some "magic" string to make jqGrid understand it is reading a MS DateTime ? Is there any particular configuration ?
Or probably we are talking about an open issue (because I read "will be fixed") ?
Thanks in advance,
Alex
15:11
Moderators
30/10/2007
Hello,
Also fixed in GitHub.
Hope in the future to use GitHub for such kind of patches
Thanks again to all.
P.S. It is quite possible that this is not the last fix
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.
23:59
10/08/2009
Hi NoWoL,
do you tested the code published from in GitHub or it seems to you that the RegEx is wrong? I don't yet tested the code one more time, but now the RegEx is exactly like in the version which I used and tested many times with different data before I posted the information here.
Probably you use frequently the form /pattern/modifier of RegEx and not constructor of RegEx with the string literal. There are some difference in coding of backslashes in the two forms. See for example "How to Use The JavaScript RegExp Object" section of this.
If you will find a bug in the code you are welcome, but please test the code and post exactly which input data will be wrong converted by the code. Which result should be and which wrong result produce the code.
Best regards
Oleg
04:11
16/01/2011
Hi Oleg,
You are correct, I did not expect the code to change from the /pattern/modifier to the RexExp object.
Is there a design document for this grid? I just upgraded from 3.6.4 to 3.8.2 for the new date formatter and I found a bug and I would like to try my hand at fixing it. This is the bug: if the value of index in a colModel contains a period e.g.: "Person.Name" the value passed (sidx) to the web service contains only "Name". It worked in 3.6.4 but it was broken in 3.6.5.
Best regards,
NoWoL
07:14
10/08/2009
Hi NoWoL,
The problem, which you describe with index having period seems for me a bug. The same problem are described here and here. I can imagine that having periods in the index can be important if database schema used on the database, but having index with period in case of pure local data (not "json" datatype and loadonce:true) and can be replaced with jsonmap. So the bug in the case makes have a simple workaround. Which scenario has you?
Nevertheless it is absolutely another problem not connected with the "Microsoft" data format. You can post additional information to the bug report to remind Tony about the problem. I am not a developer of jqGrid and I am additionally busy for at least next two weeks. So please contact Tony about the problem yourself.
Best regards
Oleg
Most Users Ever Online: 715
Currently Online:
37 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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66