DataTable如何仅显示日期而不是日期时间 [英] DataTables how do I show only date rather than datetime

查看:1725
本文介绍了DataTable如何仅显示日期而不是日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Django示例,我正在使用服务器端处理一个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):


Dec。 18,2011,11:59 pm

Dec. 18, 2011, 11:59 p.m.

我只想显示日期部分,而不是日期和时间。

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如何仅显示日期而不是日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆