I am trying to display some data in a datatable and the table script I am using is
$('#userData').dataTable({
"ajax": {
"url": "${rc.getContextPath()}/module/roles/users-list",
"dataSrc": "",
},
"columns":[
{"data": "userId"},
{"data": "applicationId"},
{"data": "username"},
{"data": "firstName"},
{"data": "userCreated"},
{"data": "createdTime"},
{"data": "updatedTime"}
],
});
the data that is received by the table is json and would be something like
[
{
"userId":179,
"applicationId":"pgm-apn",
"username":"collaborator.user3",
"password":"password1",
"email":"user@xample.com",
"firstName":"Anthony",
"lastName":"Gonsalves",
"enabled":true,
"userCreated":"sitepmadm",
"userModified":"sitepmadm",
"createdTime":1422454697373,
"updatedTime":1422454697373
},
{
"userId":173,
"applicationId":"pgm-apn",
"username":"consumer.user",
"password":"password1",
"email":"test@egc.com",
"firstName":"sherlock ",
"lastName":"homes",
"enabled":true,
"userCreated":"sitepmadm",
"userModified":"sitepmadm",
"createdTime":1422010854246,
"updatedTime":1422010854246
}
I want to display the dates as proper datetime.Currently it is getting displayed as teh same sting in the json data.Is there any way to convert that in the datatable
i have created demo using moment js and use of render function to convert json data into required format.
jsfiddle demo
also find code below:
For dot.net and javascript, you can just use like @David Sopko
You can use "render" property to format your column display http://datatables.net/reference/option/columns.render#function.
For example:
For showing the time along with the date add the code below:
I always use moment.js(http://momentjs.com/) when dealing with dates in js.
The date values returned are in unix timestamp so you need to convert them.
Here's a sample fiddle: http://jsfiddle.net/fws8u54g/