Can't sort by date-euro
Can't sort by date-euro
Hi here,
First of all, DataTables is amazing, thanks a lot for this crazy tool ! I have a bug with date-euro sorting. I need to sort timestamp date : dd/mm/yyyy hh:ii:ss and it don't work... I've read all the discussion about that on this forum, and all the solutions didn't work. I'm not a jQuery pro, maybe it's just a little mistake but, I need help..
This is the sorting function I am using :
[code]
function format_date(european_date) {
// For dates as "dd/mm/YYYY hh:ii:ss"
// First trim the date
trimed_date = european_date.replace(/^\s+/g, '').replace(/\s+$/g, '');
// Then transform it to an integer
if (trimed_date != '') {
var frDatea = trimed_date.split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
return (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
}else return 10000000000000; // = l'an 1000 ...
}
jQuery.fn.dataTableExt.oSort['date-euro-asc'] = function(x, y) {
x = format_date(x);
y = format_date(y);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['date-euro-desc'] = function(x, y) {
x = format_date(x);
y = format_date(y);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
And in the same xsl file the dataTable code :
[code]
$(document).ready(function() {
$("#tablesorter-list").dataTable({
"sScrollY": "500px",
"bScrollCollapse": true,
"bPaginate": false,
"bJQueryUI": true,
"aoColumnDefs": [
{ "sWidth": "10%", "aTargets": [ -1 ] },
{ "bSortable": false, "aTargets": [ 0 ] }
],
"oLanguage": {
"sZeroRecords": "Nous n'avons rien trouvé",
"sInfo": "Affichage de _TOTAL_ résultats",
"sInfoEmpty": "Affichage de 0 résultat",
"sInfoFiltered": "(sur _MAX_ résultats)",
"sSearch": "Recherche"
},
"aoColumns": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
{ "sType": "date-euro" }
]
});
});
[/code]
All the code is in <![CDATA[ ]]> . If someone can help me, it would be great !
First of all, DataTables is amazing, thanks a lot for this crazy tool ! I have a bug with date-euro sorting. I need to sort timestamp date : dd/mm/yyyy hh:ii:ss and it don't work... I've read all the discussion about that on this forum, and all the solutions didn't work. I'm not a jQuery pro, maybe it's just a little mistake but, I need help..
This is the sorting function I am using :
[code]
function format_date(european_date) {
// For dates as "dd/mm/YYYY hh:ii:ss"
// First trim the date
trimed_date = european_date.replace(/^\s+/g, '').replace(/\s+$/g, '');
// Then transform it to an integer
if (trimed_date != '') {
var frDatea = trimed_date.split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('/');
return (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1;
}else return 10000000000000; // = l'an 1000 ...
}
jQuery.fn.dataTableExt.oSort['date-euro-asc'] = function(x, y) {
x = format_date(x);
y = format_date(y);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['date-euro-desc'] = function(x, y) {
x = format_date(x);
y = format_date(y);
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]
And in the same xsl file the dataTable code :
[code]
$(document).ready(function() {
$("#tablesorter-list").dataTable({
"sScrollY": "500px",
"bScrollCollapse": true,
"bPaginate": false,
"bJQueryUI": true,
"aoColumnDefs": [
{ "sWidth": "10%", "aTargets": [ -1 ] },
{ "bSortable": false, "aTargets": [ 0 ] }
],
"oLanguage": {
"sZeroRecords": "Nous n'avons rien trouvé",
"sInfo": "Affichage de _TOTAL_ résultats",
"sInfoEmpty": "Affichage de 0 résultat",
"sInfoFiltered": "(sur _MAX_ résultats)",
"sSearch": "Recherche"
},
"aoColumns": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
{ "sType": "date-euro" }
]
});
});
[/code]
All the code is in <![CDATA[ ]]> . If someone can help me, it would be great !
This discussion has been closed.
Replies
Allan
Thanks,
Neal
Allan
Thanks for your help !