我想在显示一些数据 的数据表 ,我使用的表脚本
$('#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"} ], });
该表接收到的数据是json,类似于
[ { "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 }
我想将日期显示为正确的日期时间。当前它正在以相同的方式显示在json数据中。是否有任何方法可以在数据表中进行转换
您可以使用“ render”属性来设置列显示的格式http://datatables.net/reference/option/columns.render#function。
例如:
{ "data": "createdTime", "render": function (data) { var date = new Date(data); var month = date.getMonth() + 1; return (month.toString().length > 1 ? month : "0" + month) + "/" + date.getDate() + "/" + date.getFullYear(); } }