Date Sorting not working in Firefox & I. Explorer.

Date Sorting not working in Firefox & I. Explorer.

_PJ__PJ_ Posts: 7Questions: 0Answers: 0
edited November 2013 in General
Hi there,

I'm new here so first of all, just say that DataTables is really a great feature:)
Now regarding to my problem, I have a column with the format (Month Year) that is sorting properly in Chrome, but is not working in Firefox and Internet Explorer.

Here is the code:


$(document).ready(function() {
$('#resultados').dataTable( {
"sPaginationType": "full_numbers",
"aaSorting":[[2, "desc"]],
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 1,4 ] }, ],
"aLengthMenu": [[25, 50, 75, 100], [25, 50, 75, 100]],
"iDisplayLength": 100
} );
} );


Hope somebody can help me because I can't find where the problem is!
Thanks in advance

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What does your date format look like exactly? Very likely in those browsers Date.parse() doesn't support that format. Date.parse() is really only good for YYYY-MM-DD. For anything else it is implementation dependent. You are much better off using a sorting plugin:

    http://datatables.net/development/sorting
    http://datatables.net/plug-ins/sorting

    Allan
  • _PJ__PJ_ Posts: 7Questions: 0Answers: 0
    Thanks Allan,

    I found a script that may solve my problem. But I dont know how to include it in my code.
    Can you give me a hand?
    Is the plugin Month Year:

    Here is the code:

    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "monthYear-pre": function ( s ) {
    var a = s.split(' ');
    // Date uses the American "MM DD YY" format
    return new Date(a[0]+' 01 '+a[1]);
    },

    "monthYear-asc": function ( a, b ) {
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "monthYear-desc": function ( a, b ) {
    return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
    } );

    Should I save it as a separated .js file?
    How will recognize the plugin my column?
    Please help
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    There is an example of how to use sorting plug-ins here: http://datatables.net/release-datatables/examples/plug-ins/sorting_sType.html

    Allan
  • _PJ__PJ_ Posts: 7Questions: 0Answers: 0
    edited November 2013
    Thanks for reply Allan. I added the new plugin and use the example of your link as reference, but I cant make it work, and when I added the plugin code, the column titles are not sortable at all.
    Please take a look to my code, I dont know which step Im doing wrong.
    Thanks in advance





    Query.extend( jQuery.fn.dataTableExt.oSort, {
    "monthYear-pre": function ( s ) {
    var a = s.split(' ');
    // Date uses the American "MM DD YY" format
    return new Date(a[0]+' 01 '+a[1]);
    },

    "monthYear-asc": function ( a, b ) {
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "monthYear-desc": function ( a, b ) {
    return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
    } );
    $(document).ready(function() {
    $('#resultados').dataTable( {
    "sPaginationType": "full_numbers",
    "aaSorting": [] ,
    "aoColumnDefs": [
    { 'bSortable': false, 'aTargets': [ 1,4 ] },
    { "sType": "monthYear", "aTargets": [ 2 ] },
    ],
    "aLengthMenu": [[25, 50, 75, 100], [25, 50, 75, 100]],
    "iDisplayLength": 100
    } );
    } );
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Looks like you are doing it all right to me! Can you link me to the page so I can see what is going wrong please?

    Allan
  • _PJ__PJ_ Posts: 7Questions: 0Answers: 0
    Yes Allan, I can send you the link, but can it be privately? For example, to your mail?
    Thanks
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    PM me by clicking my name and then "Send Message".

    Allan
This discussion has been closed.