Can't sort by date-euro

Can't sort by date-euro

MNealMNeal Posts: 4Questions: 0Answers: 0
edited December 2013 in Plug-ins
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 !

Replies

  • MNealMNeal Posts: 4Questions: 0Answers: 0
    up !
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Please link to a test case showing the issue so we can debug it, as noted in the forum rules: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Allan
  • MNealMNeal Posts: 4Questions: 0Answers: 0
    Hi Allan, sorry I forgot about it. Here is the link http://jsfiddle.net/D3nV2/

    Thanks,
    Neal
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    No doubt I'm being really thick, but it appears to work for me if you include jQuery: http://jsfiddle.net/D3nV2/1/ . I'm missing something I guess?

    Allan
  • MNealMNeal Posts: 4Questions: 0Answers: 0
    Hi again, it works now, the problem was the split fonction in my code.

    Thanks for your help !
This discussion has been closed.