dongwo1914 2016-09-26 03:42
浏览 165

DataTable时刻不适用于排序日期时间列?

Please do not mark as duplicate as I haven't find solutions anywhere.

Following line is not working to sort date and time together in DataTable.

enter image description here

Secondly, I have used following code to make sorting working but it doesn't:

$.fn.dataTable.moment('HH:mm dd/mm/YY');
    //$.fn.dataTable.moment( 'DD-MM-YYYY HH:mm' );

and for DataTable initialization I have used following code:

$('.dataTable').DataTable({
    ordering: true,
    paging: true,
    searching: true,
    dom: 'Bftripl',
    buttons: [
        'excelHtml5',
        'csvHtml5',
        'pdfHtml5'
    ],
    "columnDefs": [
        //{ "type": "date-euro", targets: 1 }
        //{ "sType": "date-uk", targets: 1 }
    ]
});

I have added file : datetime-moment.js

None of the code working for sorting out the date column, so please anybody help or provide example for it on jsFiddle.

Thanks Friends in advanced:)

For Anan your code gives me following output: after using your updated code but can't pass data as I am feeding data into table using php....

$.fn.dataTable.moment( 'HH:mm DD/MM/YYYY' );
$('.dataTable').DataTable({
    ordering: true,
    paging: true,
    searching: true,
    dom: 'Bftripl',
    buttons: [
        'excelHtml5',
        'csvHtml5',
        'pdfHtml5'
    ]
});

but unfortunately didn't worked:( enter image description here

  • 写回答

1条回答 默认 最新

  • dqyuipw44576 2016-09-26 08:04
    关注

    it's because your time format is wrong;look this:

    there are my example for it:http://live.datatables.net/xedayaxi/1/edit

    according to author,put the data in html ,just look this example:

    $(document).ready( function () {
    
      $.fn.dataTable.moment( 'HH:mm DD/MM/YYYY' );
       
      var table = $('#example').DataTable({
        ordering: true,
        paging: true,
        searching: false,
    
      });
    } );
    <!DOCTYPE html>
    <html>
      <head>
        <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    
        <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
        <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
        <script src="//cdn.datatables.net/plug-ins/1.10.12/sorting/datetime-moment.js"></script>
        <meta charset=utf-8 />
        <title>DataTables - JS Bin</title>
      </head>
      <body>
        <div class="container">
    <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>time</th>
    
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>time</th>
    
                </tr>
            </tfoot>
            <tbody>
                <tr>
                    <td>19:46 30/06/2016</td>
    
                </tr>
                <tr>
                    <td>14:46 29/06/2016</td>
    
                </tr>
                <tr>
                    <td>19:46 29/07/2018</td>
    
                </tr>
                <tr>
                    <td>02:16 29/06/2016</td>
    
                </tr>
                <tr>
                    <td>16:46 29/06/2017</td>
    
                </tr>
    
              
            </tbody>
        </table>
        </div>
      </body>
    </html>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来