0

我在对日期列进行排序时遇到问题。我的日期是这种格式

Y-m-d H:i:s

我得到这个输出:

2012-04-14 23:07:00
2012-01-14 22:40:14
2012-03-09 19:03:20
2012-03-12 16:00:28
2012-05-01 16:09:38
2012-02-11 05:07:08
2012-01-17 15:15:09
2012-03-10 16:02:20
2012-02-09 14:33:19

这是我的初始化:

$(document).ready(function() {
        oTable=$('#jphit').dataTable( {
          "sDom": 'T,C<"clear">lfrtip',
             "oTableTools": {
            "sSwfPath": "swf/copy_csv_xls_pdf.swf"
        },
             "oColVis": {
             "buttonText": "Extend table",
            "activate": "mouseover"
        },
        "aoColumnDefs": [
      { "bVisible": false, "aTargets": [ 2 , 4 , 6] }
    ],
            "aoColumns": [
              {
                "mDataProp": null,
                "sClass":"center",
                "sDefaultContent": '<img src="images/plus-icon.png" style="width:27px; height:27px;display: inline;">'
              },
              { "mDataProp": 0 }, //date column
              { "mDataProp": 1 },
              { "mDataProp": 2 },
              { "mDataProp": 3 },
              { "mDataProp": 4 },
              { "mDataProp": 5 },
              { "mDataProp": 6 }
            ],
            "aaSorting": [[0,'desc']], //sort date column
            "bProcessing": true,
            "bSort": true,
            "sPaginationType": "full_numbers",
            "bServerSide": true,
            "sScrollY": "500px",
            "bDeferRender": true,
            "sAjaxSource": "history_table.php"
        } );

这是我的 PHP 部分:

$aRow[$iTimestampCol] = date( 'Y-m-d H:i:s', $aRow[$iTimestampCol] );
4

1 回答 1

1

我想你应该看到这个http://datatables.net/plug-ins/sorting。有一些示例如何按日期排序。

于 2012-12-06T10:54:36.017 回答