Date-UK Sorting Plugin not working
Date-UK Sorting Plugin not working
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,
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,
This discussion has been closed.
Replies
Allan
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,
Allan
You're right, upgrading to 1.9 it works fine! Thanks a lot.