jqGrid显示13位数而不是格式日期

时间:2011-08-22 19:04:37

标签: date jqgrid format onload

我的jqGrid在初始网格加载时显示(1303153262000)。但是,当列排序时,日期格式正确(8月18日上午11:43)。有没有办法让网格在加载时自动进行格式化?

这正是日期从服务器返回时的样子(2011-04-18 19:01:02)。

这是我正在使用的jqGrid列模型:

jQuery("#list4").jqGrid({
datatype: "local",
height: 250,
colNames:['Original ID','Date Created', 'Type', 'Title'],
colModel:[  
{name:'Id',index:'Id'},
{name:'cDate',index:'cDate', width:120, sorttype:'date', formatter:'date',     formatoptions: {srcformat:'M d h:i', newformat:'M d g:i A'}},  
{name:'xData',index:'xData', width:120}, 
{name:'zData',index:'zData', width:140}
],
rowNum: 1000,
multiselect: true,
toolbar: [true, "top"]
});

任何帮助将不胜感激!感谢。

编辑:

@Oleg这里是服务器端的数据:

2011-04-18 19:01:02
2011-04-18 19:01:28
2011-01-07 01:00:20
2011-04-18 19:01:02
2011-04-18 19:01:28
2011-01-07 01:00:20
2011-06-29 22:20:29
2011-06-29 21:47:55

以下是返回jqGrid时的样子:

Test: 1303153262000
Test: 1303153288000
Test: 1294362020000
Test: 1303153262000
Test: 1303153288000
Test: 1294362020000

我是否必须使用返回的结果创建一个新数组,其功能是将纪元日期更改为我想要的日期格式?必须这样做是没有意义的,因为jqGrid显然具有该功能,但仅在用户点击排序时。有没有办法让jqGrid在页面加载时执行此操作?

我把它从日食中拉出来。我正在使用名为NotesArray的列表/数组。这是从服务器返回的数组:

NotesArray:{Original_Created_Date__c=2011-07-01 01:06:55, Title__c=Title of message 1 00001073: 06/30/2011 18:07:07, Type__c=Task, Id=a0D8000000Na0Q0EAJ, Originating_Id__c=00T8000001nuEzPEAU}
NotesArray:{Original_Created_Date__c=2011-06-30 22:14:48, Title__c=Title of message 2 00001072: 06/30/2011 15:15:00, Type__c=Task, Id=a0D8000000Na0Q1EAJ, Originating_Id__c=00T8000001nuCccEAE}
NotesArray:{Original_Created_Date__c=2011-06-30 21:24:47, Title__c=Title of message 3 00001071: 06/30/2011 14:25:00, Type__c=Task, Id=a0D8000000Na0Q2EAJ, Originating_Id__c=00T8000001nuB5cEAE}
NotesArray:{Original_Created_Date__c=2011-06-30 21:19:48, Title__c=Title of message 4 00001070: 06/30/2011 14:20:00, Type__c=Task, Id=a0D8000000Na0Q3EAJ, Originating_Id__c=00T8000001nuBFiEAM}
NotesArray:{Original_Created_Date__c=2011-06-30 21:14:47, Title__c=Title of message 5 00001069: 06/30/2011 14:15:00, Type__c=Task, Id=a0D8000000Na0Q4EAJ, Originating_Id__c=00T8000001nuAzDEAU}
NotesArray:{Original_Created_Date__c=2011-06-30 21:09:47, Title__c=Title of message 6 00001068: 06/30/2011 14:10:00, Type__c=Task, Id=a0D8000000Na0Q5EAJ, Originating_Id__c=00T8000001nuASSEA2}

将回报更改为JSON:

{"rows": [{"ObjectType": "Event","CreatedDate": "2011-01-03 09:16:51","ActivityType": "Call","OriginalId": "00U8000000Elxb4EAB","Title": "TEST EVENT"},{"ObjectType": "Event","CreatedDate": "2011-01-03 08:53:22","ActivityType": "Meeting","OriginalId": "00U8000000ElxY9EAJ","Title": "sadfasdf"},{"ObjectType": "Event","CreatedDate": "2011-01-03 08:51:04","ActivityType": "Meeting","OriginalId": "00U8000000ElxXkEAJ","Title": "werwrasdf"},{"ObjectType": "Task","CreatedDate": "2011-01-06 14:42:43","ActivityType": "Call","OriginalId": "00T8000001bce9VEAQ","Title": "test"},{"ObjectType": "Task","CreatedDate": "2011-01-03 08:50:41","ActivityType": "Meeting","OriginalId": "00T8000001aiqAXEAY","Title": "asdfasdfasf"},{"ObjectType": "Task","CreatedDate": "2011-01-03 08:50:29","ActivityType": "Call","OriginalId": "00T8000001aiqAcEAI","Title": "asdfsaf"},{"ObjectType": "Task","CreatedDate": "2011-01-03 08:52:55","ActivityType": "Call","OriginalId": "00T8000001aiqBuEAI","Title": "asdfsaf"},{"ObjectType": "Note","CreatedDate": "2011-08-22 15:17:11","ActivityType": "Note","OriginalId": "0028000000T03CUAAZ","Title": "Mondays Best"},{"ObjectType": "Note","CreatedDate": "2011-08-18 11:43:25","ActivityType": "Note","OriginalId": "0028000000SzwIjAAJ","Title": "Note Test"}]}

1 个答案:

答案 0 :(得分:1)

如果日期来自服务器“2011-04-18 19:01:02”,为什么使用'M d h:i'代替'Y-m-d H:i:s'作为srcformat的值?

如果使用

formatoptions: {srcformat:'Y-m-d H:i:s', newformat:'M d g:i A'}

无法解决您的问题,您应该包含用于填充“cDate”列的输入数据的确切示例。

更新:您可以加载直接在jqGrid中发布的JSON数据。请参阅修改后的演示here。你需要的只是在jqGrid中使用列中的名称,就像在JSON数据中一样,另外你应该使用

loadonce: true,
jsonReader: {
    repeatitems: false,
    id: "OriginalId",
    root: "rows",
    page: function (obj) { return 1; },
    total: function (obj) { return 1; },
    records: function (obj) { return obj.length; }
}

在演示中,我添加了一个列,因为我不知道您希望在ObjectType列中显示ActivityType还是'Type'。您可以从jqGrid(不适用于JSON)中删除任何不需要显示的列。例如,如果OriginalId列中的包含对用户不感兴趣,则可以从网格中删除相应的列。