Sort jquery datatable.net by date [duplicate]

0

I'm doing the ordering of the ORDER column like this:

"order": [[3, "asc"]]

Note that the ordering of COLUMN is not is correct:

TheorderingoftheORDERcolumnneedstolooklikethis:

    
asked by anonymous 07.11.2016 / 14:11

1 answer

2

Depending on the version or files you use, it does not have the extension to sort by date.

To change, simply add the DateTable date-euro in your project and add the column you should be ordered, example:

$('#example').dataTable( {
     columnDefs: [
       { type: 'date-euro', targets: 0 }
     ]
  });

If you want to add only the code, the extension code is this:

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "date-euro-pre": function ( a ) {
        var x;

        if ( $.trim(a) !== '' ) {
            var frDatea = $.trim(a).split(' ');
            var frTimea = (undefined != frDatea[1]) ? frDatea[1].split(':') : [00,00,00];
            var frDatea2 = frDatea[0].split('/');
            x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
        }
        else {
            x = Infinity;
        }

        return x;
    },

    "date-euro-asc": function ( a, b ) {
        return a - b;
    },

    "date-euro-desc": function ( a, b ) {
        return b - a;
    }
} );

See an example in JsFiddle.

    
07.11.2016 / 14:37