Sorting by Date (UK) with various number of columns
Sorting by Date (UK) with various number of columns
Great plugin! Well done Allan.
I'm using the plugin on one of my project - and the date-sorting is driving me crazy! ;)
Basically, I have tables with various number of columns (between 2 and 8 columns).
The date column is always the first column - is there any way to use set UK date sorting on first column without knowing the exact number of columns?
According to the doc here: http://datatables.net/usage/columns
the following example should work just fine, but it does not:
Live demo here: http://jsfiddle.net/MrTest/yM24R/34/
[code]
// UK Date Sorting
jQuery.fn.dataTableExt.oSort['uk_date-asc'] = function(a, b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a, b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#table').dataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"aoColumnDefs": {
"aTargets": [0] ,
"sType": "uk_date"
}
})
[/code]
Thanks.
Peter
I'm using the plugin on one of my project - and the date-sorting is driving me crazy! ;)
Basically, I have tables with various number of columns (between 2 and 8 columns).
The date column is always the first column - is there any way to use set UK date sorting on first column without knowing the exact number of columns?
According to the doc here: http://datatables.net/usage/columns
the following example should work just fine, but it does not:
Live demo here: http://jsfiddle.net/MrTest/yM24R/34/
[code]
// UK Date Sorting
jQuery.fn.dataTableExt.oSort['uk_date-asc'] = function(a, b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a, b) {
var ukDatea = a.split('/');
var ukDateb = b.split('/');
var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#table').dataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"aoColumnDefs": {
"aTargets": [0] ,
"sType": "uk_date"
}
})
[/code]
Thanks.
Peter
This discussion has been closed.