【发布时间】:2017-08-05 14:26:03
【问题描述】:
当服务器将日期存储为纪元时间时,似乎没有正确呈现日期。 jqrid 格式使用它“u”或“U”,但它不会在网格上呈现正确的日期。
我在 Fiddler 创建了演示:http://jsfiddle.net/SalesforceDev/duooa5oy/2/
$(function () {
"use strict";
var mydata = [
{
data: 1489449600000,
status: "OPEN"
},
{
data: 1489449600000,
status: "ENTERED"
}];
$("#grid").jqGrid({
data: mydata,
colModel: [
{ name: 'act', template: "actions" },
{
name: 'data',
editrules: { required: true },
formatter: 'date',
formatoptions: {
srcformat: 'u',
newformat: 'd/m/Y H:i'
},
editable: true,
editoptions: {
dataInit: function (el) {
$(el).datetimepicker({
locale: 'en-GB',
//debug: true,
widgetPositioning: {
horizontal: 'auto',
vertical: 'auto'
},
widgetParent: '#outer'
});
// fix position of the datetimepicker
$(el).bind("dp.show", function () {
var $datepicker = $("#outer .bootstrap-datetimepicker-widget");
if ($datepicker.length > 0) {
$datepicker.css("top",
this.getBoundingClientRect().top +
window.pageYOffset +
$(this).outerHeight());
}
});
}
}
},
{
name: 'status',
width: 180
}
],
iconSet: "fontAwesome",
guiStyle: "bootstrap",
hoverrows: false,
pager: true
});
//
$("#show-date").text("1489449600000 ==>"+(new Date(1489449600000)));
});
更新 1 当我尝试以下 fotmatter 选项时,网格停止渲染并引发异常。演示:http://jsfiddle.net/SalesforceDev/duooa5oy/3/
formatter: function (cellval, opts) {
var date = new Date(cellval);
opts = $.extend({}, $.jgrid.formatter.date, opts);
return $.fmatter.util.DateFormat("", date, 'd-M-Y', opts);
},
chrome 上的异常:
Uncaught TypeError: Cannot read property 'DateFormat' of undefined
at HTMLTableElement.formatter (VM317:111)
at HTMLTableElement.d.formatter (jquery.jqgrid.src.js:3369)
at aa (jquery.jqgrid.src.js:2276)
at HTMLTableElement.parseDataToHtml (jquery.jqgrid.src.js:2334)
at HTMLTableElement.Z (jquery.jqgrid.src.js:3926)
at L (jquery.jqgrid.src.js:4404)
at HTMLTableElement.ca (jquery.jqgrid.src.js:4476)
at HTMLTableElement.<anonymous> (jquery.jqgrid.src.js:5787)
at Function.each (VM312 jquery.min.js:2)
at r.fn.init.each (VM312 jquery.min.js:2)
at r.fn.init.b.fn.jqGrid (jquery.jqgrid.src.js:2505)
at HTMLDocument.<anonymous> (VM317:101)
at j (VM312 jquery.min.js:2)
at k (VM312 jquery.min.js:2)
更新 3
现在使用格式u1000 之后,但是当您提交保存操作并且从网格行中的对象读取日期时给出了错误的日期!
【问题讨论】:
标签: jquery jqgrid free-jqgrid