Sorting date in datatable

后端 未结 5 1596
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 17:50

I\'m trying to sort dates in my datatable like DD/MM/YYYY (day, month, year) . I was following https://datatables.net/plug-ins/sorting/ .

but all the

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 18:05

    Following Plasebo's example works, but in my case the MySQL DATE_FORMAT was sorting on month value, not entire date. My solution was to remove the DATE_FORMAT from my SQL statement.

    $(document).ready(function() {
      $.fn.dataTable.moment('DD/MM/YY');
      $('.happyTable').DataTable({
            "ordering": true,
            "order": [[ 1, "desc" ]],
      });
    });
    

    DATE_FORMAT(date,'%m/%d/%Y')

    "2003-12-30 00:00:00" results in "12/30/2003" but sorts on month value.

提交回复
热议问题