sorting german date - please help
sorting german date - please help
Hey guys,
sorry if my question has already been discussed - unfortunately I could not find an answer for my problem.
Can someone please help me out, I am trying to sort a column with a german date and I was not able to get the Date-Plugin working - and.. I have no clue...
01.02.2011 (dd.mm.YY) This is the date format. I used something like this:
[code]
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() {
$('#events').dataTable( {
"col2": [
null,
null,
null,
{ "sType": "uk_date" },
null
]
} );
});
[/code]
Do I have to modify the date format or the plugin to detect the date in column "col2" ?
Thanks much for any help!
patte
sorry if my question has already been discussed - unfortunately I could not find an answer for my problem.
Can someone please help me out, I am trying to sort a column with a german date and I was not able to get the Date-Plugin working - and.. I have no clue...
01.02.2011 (dd.mm.YY) This is the date format. I used something like this:
[code]
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() {
$('#events').dataTable( {
"col2": [
null,
null,
null,
{ "sType": "uk_date" },
null
]
} );
});
[/code]
Do I have to modify the date format or the plugin to detect the date in column "col2" ?
Thanks much for any help!
patte
This discussion has been closed.
Replies
The date format that yo have there is using a dot as a separator, where as the plug-in above is using a slash. It should simply be a case of change the 'split':
[code]
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() {
$('#events').dataTable( {
"col2": [
null,
null,
null,
{ "sType": "uk_date" },
null
]
} );
});
[/code]
Allan
thanks much for the quick response!
Unfortunately that didn`t work - the date column has still been sorted the wrong way... mixing the years ...
sorting_asc results in :
01.02.2011
03.01.2011
04.01.2011
07.12.2010
10.01.2011
11.01.2011
13.12.2011
14.12.2010
18.11.2010
20.12.2011
any ideas?
Thanks much
pate
Sorry one thing I should have picked up on and missed - you've got 'col2' as a parameter which is being passed into DataTables - which DataTables doesn't recognise. If you change that 'col2' to 'aoColumns' - hopefully that will do the trick.
Allan
ah, you`re right!
And I also changed the aoCollumns-settings to match die table structure.
Thanks for the support
patte
[code]
$(document).ready(function() {
$('#events').dataTable( {
"aoColumnDefs": [
{ "sType": "uk_date", "aTargets": [ 3 ] } ]
} );
});
[/code]
Regards,
Allan