javascript - jqGrid;以 json 格式获取的日期未显示在表中。也无法格式化日期

标签 javascript jquery json jqgrid

这是我第一次使用 jqGrid。日期根本没有显示在表格中。数据以json格式编码。在调试时,我发现获取的日期是 unicode(不确定)格式,基本上是一个 13 位数字。 我尝试过使用 srcformat 作为“U”或“u”。但两者都不起作用。我尝试创建自定义格式化程序,但返回未定义的日期。

例如,JSON 值为“1380556800000”。另外,我想提一下,java 对象是 Timestamp 类型。

如果您能指出我在这里到底做错了什么,那就太好了。 提前致谢

function searchSchePtn(){
    var sParam = {
    outPtnId : $('#outPtnId').val(),
    floutScheCd : $('#scheCd').val(),
    floutScheNm : $('#scheNm').val(),
    schePtn : $('#schePtn').val(),
    status : $('#status').val(),
};

var schePtnList = null;

SchePtnAccessor.getFloutSchePtnList(sParam, {
    callback : function(value) {
        schePtnList = JSON.parse(value);
    },
    async : false
});

$('#schePtnList').jqGrid('GridUnload');
$('#schePtnList').jqGrid(
        {
            data : schePtnList,
            datatype : 'local',
            height : 250,
            rowNum : 10,
            rowList : [ 10, 20, 30 ],
            colNames : [ 'Schedule Id', lang.getMessage('出力パターン名称', 'Output Pattern Name'), 'Schedule Code', 'Schedule Name', 'Schedule Pattern', 'Start Date', 'Execution Time', 'Status'],
            colModel : [ {
                name : 'floutScheId',
                index : 'floutScheId',
                hidden : true,
        },{
                name : 'outPtnName',
                index : 'outPtnName',
                width : 150,
                sorttype : "String"
            }, {
                name : 'floutScheCd',
                index : 'floutScheCd',
                width : 150,
                sorttype : "String"
            }, {
                name : 'floutScheNm',
                index : 'floutScheNm',
                width : 150,
                sorttype : "String"
            }, {
                name : 'schePtn',
                index : 'schePtn',
                width : 50,
                sorttype : "String"
            }, {
                name : 'sDate',
                index : 'sDate',
                width : 100,
                formatter: 'date',
                formatoptions: {srcformat:'U', newformat:'d-M-y H:i'}
            } , {
                name : 'actTime',
                index : 'actTime',
                width : 50,
                sorttype : "String"
            }, {
                name : 'status',
                index : 'status',
                width : 50,
                sorttype : "String"
            }],
            pager : '#schePtnListPager',
            viewrecords : true,
            gridview : true,
        });

};

最佳答案

我认为这个问题之前已经得到解答...不确定您是否有同样的问题,但请尝试看看这个... jqgrid date formatting

Updated

name: 'myDate',
        index: 'myDate',
       align: 'left',
          sortable: true,
          formatter: 'date',
         formatoptions: 
        {srcformat: 'u', newformat: 'd/m/Y H:i:s'},
          width: 70,  

jsFiddle

关于javascript - jqGrid;以 json 格式获取的日期未显示在表中。也无法格式化日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19973464/

相关文章:

javascript - JQuery Datepicker - 在多个字段中显示日期

javascript - 如何在我的网站上通过 ajax 加载内容时显示预加载器

jquery - Ruby on Rails 通过 ajax 搜索

android - 在 jsonArray Android 中分组 jsonObjects

javascript - Angular JS 可调整大小的 div 指令,用于调整顶部和底部 div 大小的调整 handle

javascript - 带有文本框的范围 slider Jquery 和 CSS

javascript - 使用 jQuery 在单击按钮上传递值

javascript - Aurelia 绑定(bind) Change.delegate 未触发(JQueryUI Datepicker)

json - Flutter 将字符串转换为数组

python - 使用 Python 将值插入到 json 文件中的特定位置