Date format in jQuery jqGrid
I have a date field that is coming across in the JSON as "August, 13 2012 12:58:29″ I am using jqGrid 3.7.2 and cannot upgrade. What do I need to adjust in my colModel to have the date format on the client side in this format "08/14/2012"?
I tried using: formatter: 'date', formatoptions: { srcformat: '', newformat: ''}
but I can't get the right combination for srcformat and newformat. It always comes out weird.
THANKS
You use very bad date format "August, 13 2012 12:58:29"
as the input for jqGrid. Good date format which is recommended to send between the server and the client is some language independent and locale independent format like 2012-08-13T15:58:29Z
(see ISO 8601).
Another problem is that jqGrid 3.7.2 have no support of 'F'
format (or bugs in the implementation). You can compare the code of DateFormat and code of parseDate with the corresponding code of jqGrid 3.7.2. If you would update the code of the function in you copy of jqGrid 3.7.2 your problem should be solved (See some my bug reports for example: here and here for example).
PS: If you want to receive answers on your questions in the future you should start the "accept" the answers. It's just one click what you need to do.
I have resolved the NaN/NaN/NaN issue for date-field by manually altering the jquery.jqgrid.src.js (4.5.2). In my case, the json response would return date in an 'ISO1860Long'. It used to work till the 4.1.2 jqgrid version
Search for "parseDate" function; goto the line after :
if( opts.masks.hasOwnProperty(format) ) { format = opts.masks[format]; }
if(date && date != null) {
and add the below if check :
if(date.constructor === Number) {
if(String(format).toLowerCase() == "u") {
date = date*1000;
}
timestamp = new Date(date);
} else
before the existing :
if( !isNaN( date - 0 ) && String(format).toLowerCase() === "u") {
you can translate the changes to jquery.jqgrid.min.js yourself IF needed
链接地址: http://www.djcxy.com/p/25950.html上一篇: jqGrid日期过滤和排序
下一篇: jQuery jqGrid中的日期格式