My jqGrid is showing (1303153262000) on the initial grid load. However when the column is sorted the date is correctly formatted to (Aug 18 11:43 AM). Is there a way to get the grid to do this formatting automatically when it loads?
This is exactly what the date looks like as it is returned from the server (2011-04-18 19:01:02).
Here is the jqGrid column model i am using:
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"]
});
Any help would be greatly appreciated! Thanks.
Edit:
@Oleg here is what the data looks like on the server side:
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
And here is what it looks like when returned into the jqGrid:
Test: 1303153262000
Test: 1303153288000
Test: 1294362020000
Test: 1303153262000
Test: 1303153288000
Test: 1294362020000
Am i going to have to create a new array with the returned results with a function to change the epoch date to the date format i want? Having to do so would not make sense as jqGrid obviously has that functionality, but only when a user clicks sort. Is there a way to make jqGrid do this when the page loads?
I pulled this from eclipse. I am using a list/array called NotesArray. This is the array that is returned from the server:
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}
Changed the return to 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"}]}
If the date come from the server as ‘2011-04-18 19:01:02’ why you use
'M d h:i'instead of'Y-m-d H:i:s'as the value ofsrcformat?If the usage of
will not solve your problem you should include the exact example of the input data which you use to fill the ‘cDate’ column.
UPDATED: You can load the JSON data which you posted directly in the jqGrid. See the modified demo here. What you need is just to use in the jqGrid the names on columns like in the JSON data and additionally you should use
In the demo I added one more column because I don’t know whether
ObjectTypeorActivityTypeyou want display in the'Type'column. You can remove from jqGrid (not for JSON) any column which you not need to display. For example if the contain from theOriginalIdcolumn are not interesting for the user you can remove the corresponding column from the grid.