问题描述
根据,我正在使用服务器端处理一个href =http://www.datatables.net/index =nofollow> DataTables 。我以这种格式'yyyy-mm-dd hh:mm:ss'返回日期时间值。这些日期时间值目前显示为(例如):
I'm using server side processing as per the Django example in DataTables. I return datetime values in this format 'yyyy-mm-dd hh:mm:ss'. These date time values are currently displayed like this (for example):
我只想显示日期部分,而不是日期和时间。
I would like to display just the date part rather than both date and time.
这是我在我的html页面中有的:
This is what I have in my html page:
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function() {
$('#certs-table').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/cars/get_cars_list/",
"iDisplayLength": 10,
"aoColumnDefs": [
{ "aTargets": [0], "bVisible": false, "bSearchable": false},
{
"aTargets": [1],
"fnRender": function ( oObj ) {
return '<a href=\"/cars/' + oObj.aData[0] + '/\">' + oObj.aData[1] + '</a>';
},
"bSearchable": true,
},
{ "aTargets": [2], "bSearchable": true},
{ "aTargets": [3], "bSearchable": false, "sType": 'date'},
]
});
} );
/* ]]> */
</script>
日期是第4列,即aTarget [3]。
The date is is the 4th column, i.e., aTarget[3].
请问如何显示日期部分?我昨天才开始使用DataTables / JQuery,所以真的很赞赏一个例子。谢谢。
How do I display just the date portion please? I only started using DataTables/JQuery yesterday, so would really appreciate an example. Thanks.
推荐答案
我认为最好的选择是转换数据服务器端,只需返回所需的日期格式,但你也可以
I think that the best whay would be to convert data server side and just return the date format you want, but you could also
{ "aTargets": [3],
"bSearchable": false,
"sType": 'date',
"fnRender": function ( oObj ) {
var javascriptDate = new Date(oObj.aData[0]);
javascriptDate = javascriptDate.getDate()+"/"+javascriptDate.getMonth()+"/"+javascriptDate.getFullYear();
return "<div class= date>"+javascriptDate+"<div>";
}
}
这篇关于DataTable如何仅显示日期而不是日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!