Date-UK Sorting Plugin not working

Date-UK Sorting Plugin not working

mfernan80mfernan80 Posts: 3Questions: 0Answers: 0
edited April 2014 in Plug-ins
Hi all,

I'm trying to use a Sorting Plugin (date-uk) but it is not working for me...

Using Datatable debugger, the debug code is : uzudex

This is my code sample:

Outside document.ready section:

[code]

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));
}
} );
[/code]

Inside document.ready section:

[code]
oTable = $('#datos_avisos').dataTable({
"bJQueryUI": true,
"iDisplayLength": 20,
"sPaginationType": "full_numbers",
"aaSorting": [[ 2, "asc" ]],
"aoColumnDefs": [{ "sWidth": "250px", "aTargets": [ 0 ] },{ "sWidth": "250px", "aTargets": [ 1 ] }, { "sWidth": "90px", "sType": "date-eu", "aTargets": [ 2 ] },{ "sWidth": "60px", "aTargets": [ 3 ] }, { "sWidth": "90px", "sType": "date", "aTargets": [ 4 ]}, { "sWidth": "60px", "aTargets": [ 5 ] }]

});
[/code]

If I use normal SQL date format (yyyy-mm-dd) and without plugin (so "sType"="date" in column 2), the rows are sorted properly, but when i change the date format to be shown to dd/mm/yyyy, and applied the plugin and "sType"="date" in column 2, there is no way to sort properly. In fact, the sort is only done by the dd (probably like a string...).

This is the result (only column 2 shown) of asc sorting:
02/04/2013
04/02/2013
05/02/2013
05/02/2014
10/04/2014
16/05/2013
26/02/2013
31/01/2013

And this is the correct result if i use defaults Type date with yyyy-mm-dd:
2013-01-31
2013-02-04
2013-02-05
2013-02-26
2013-04-02
2013-05-16
2014-02-05
2014-04-10

I have also tried with date-eu plugin, but the result is the same.

Any ideas? My version of jquery.dataTables.min.js is 1.8.1

Thanks a lot and regards,

Replies

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin
    Can you link to a test case showing the issue please.

    Allan
  • mfernan80mfernan80 Posts: 3Questions: 0Answers: 0
    http://www.limpiezascade.es/admin/testDT.php

    You can see it properly in Column 2 (starting from 0) of 1st table. It is sorted asc by default, but toggling asc/desc sorting you will see the incorrect sorting.

    Regards,
  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin
    I think the issue is that you are using a very old version of DataTables - v1.8.1. Please try updating to v1.9 or the new 1.10 rc1.

    Allan
  • mfernan80mfernan80 Posts: 3Questions: 0Answers: 0

    You're right, upgrading to 1.9 it works fine! Thanks a lot.

This discussion has been closed.