user1034127 user1034127 - 8 months ago 21
Javascript Question

datatable, how to display table sorted by a column in this date format?

I would like to display the table sorted by a column called

that has this format :



The above date format can be parsed by Date.parse(). So, if you have some columns like this :


you can make a simple custom sorting plugin and use it for that particular column :

$.fn.dataTableExt.oSort['time-date-sort-pre'] = function(value) {      
    return Date.parse(value);
$.fn.dataTableExt.oSort['time-date-sort-asc'] = function(a,b) {      
    return a-b;
$.fn.dataTableExt.oSort['time-date-sort-desc'] = function(a,b) {
    return b-a;
var table = $('#example').DataTable({
    columnDefs : [
        { type: 'time-date-sort', 
          targets: [0] 

demo ->