DeferRender date column sort

DeferRender date column sort

JohnEzlabJohnEzlab Posts: 17Questions: 4Answers: 0

I'm using deferRender to populate my datatable however I believe I am still trying to accomplish my sorting on the client side (not server side).

Previously I've used HTML5 data attributes (http://www.datatables.net/examples/advanced_init/html5-data-attributes.html) but I'm not sure how I could use that with deferRender.

I have tried to use the datetime-moment.js plugin (https://datatables.net/blog/2014-12-18) but no sorting is applied whatsoever to the date column with this applied (the other table columns still sort).

I define my table with:

$.fn.dataTable.moment( 'DD/MM/YYYY' );

$("#my_table").dataTable({
  dom: "Bfrtip",
  ajax: {
    "url": $('#my_table').data('json-source'),
    "dataSrc": ""
  },
  deferRender: true
});

Answers

  • JohnEzlabJohnEzlab Posts: 17Questions: 4Answers: 0

    I still haven't been able to figure out how to get date column sorting working with deferRender and have raised the question also on Stackoverflow: http://stackoverflow.com/questions/38195202/datatables-date-sort-with-deferrender

  • JohnEzlabJohnEzlab Posts: 17Questions: 4Answers: 0

    Our solution:

    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
      "date-uk-pre": function ( a ) {
        var ukDatea = a.split('/');
        return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
      },
    
      "date-uk-asc": function ( a, b ) {
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
      },
    
      "date-uk-desc": function ( a, b ) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
      }
    });
    
    $("#my_table").dataTable({
      dom: "Bfrtip",
      ajax: {
        "url": $('#my_table').data('json-source'),
        "dataSrc": ""
      },
      deferRender: true,
      aoColumns: [
        null,
        null,
        null,
        { sType: "date-uk" },
        null,
        null,
        null,
        null
      ]  
    });
    
This discussion has been closed.