Sort date in datatable

I am trying to sort dates in my data table, for example DD/MM/YYYY(day, month, year). I followed https://datatables.net/plug-ins/sorting/ .

but all date sortings are outdated and point to the datetime plugin: https://datatables.net/blog/2014-12-18

I cannot get the datetime plugin to work for sorting. I tried the old way, with a date. Initialization is as follows:

var historiektable = $('#dataTableHistoriek').DataTable({
    "paging" : false,
    "ordering" : true,
    "scrollCollapse" : true,
    "searching" : false,
    "columnDefs" : [{"targets":3, "type":"date"}],
    "bInfo": true
});

Without sorting, the table results are displayed as follows:

Without sorting, I get this from the backend

When I put ordering:true2 dates of 2016, they appear somewhere else on the list (therefore not in the order you expect)

With sorting on date

When everything indicated the moment , I thought that I needed to deal with this. But I'm not sure how.

- $.fn.dataTable.moment('DD.MM.YYYY');, , fn ?

- , ?

+4
4

date-eu DD/MM/YY.

JS //cdn.datatables.net/plug-ins/1.10.11/sorting/date-eu.js :

var historiektable = $('#dataTableHistoriek').DataTable({
    "paging" : false,
    "ordering" : true,
    "scrollCollapse" : true,
    "searching" : false,
    "columnDefs" : [{"targets":3, "type":"date-eu"}],
    "bInfo": true
});
+5

Gyrocode.com . , Moments.js, . date-eu DataTables, .

, // : , - .

var table = $('#example-table').DataTable({
    columnDefs: [{ 'targets': 0, type: 'date-euro' }],
    order: [0, 'desc'],
});

JS date-euro . "columnDefs" , , - : target = , , type = - . , "", , .

+1

. : https://codepen.io/arnulfolg/pen/MebVgx

//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js //cdn.datatables.net/plug-ins/1.10.12/sorting/datetime -moment.js datatable

:

$.fn.dataTable.moment('DD/MM/YY');
$('#example').DataTable({ 
       "order": [[ 3, "desc" ]] 
    }); 
0

Plasebo , MySQL DATE_FORMAT , . DATE_FORMAT SQL.

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

DATE_FORMAT (, "% m/% d/% Y")

"2003-12-30 00:00:00" "30.12.2003", .

0

All Articles