Date (dd/mm/YYY hh:ii:ss) Plugin don't work
Date (dd/mm/YYY hh:ii:ss) Plugin don't work
baeckerman83
Posts: 4Questions: 1Answers: 0
Hi!
I'll use the Date (dd/mm/YYY hh:ii:ss) plugin, but it didn't sort the collum. In another collum the Date (dd/mm/YYYY) works fine.
Where is my mistake?
[code]
jQuery('#admin').dataTable({
"aoColumnDefs": [
{ "sType": "date-euro", "aTargets": [ 3 ] },
{ "sType": "uk_date", "aTargets": [ 11 ] },
{ "sType": "uk_date", "aTargets": [ 12 ] }
]
});
});
[/code]
I'll use the Date (dd/mm/YYY hh:ii:ss) plugin, but it didn't sort the collum. In another collum the Date (dd/mm/YYYY) works fine.
Where is my mistake?
[code]
jQuery('#admin').dataTable({
"aoColumnDefs": [
{ "sType": "date-euro", "aTargets": [ 3 ] },
{ "sType": "uk_date", "aTargets": [ 11 ] },
{ "sType": "uk_date", "aTargets": [ 12 ] }
]
});
});
[/code]
This discussion has been closed.
Replies
I was running into the same problem, solved it by slightly changing the code of the plugin.
First I extracted the splitting part into a separate function. Then I changed the concatenation of the date and time parts (see the assignment to x). I also made the seconds part (frTimea[2]) optional.
[code]
function splitAndAdd(a){
var frDatea = trim(a).split(' ');
var frTimea = frDatea[1].split(':');
var frDatea2 = frDatea[0].split('.');
var x = frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1]
if (frTimea[2]) x = x + frTimea[2];
return x;
}
[/code]
At last, change the sorting functions to call the new splitAndAdd function:
[code]
jQuery.fn.dataTableExt.oSort['date-euro-asc'] = function(a, b) {
if (trim(a) != '') {
var x = splitAndAdd(a);
} else {
var x = 10000000000000; // = l'an 1000 ...
}
if (trim(b) != '') {
var y = splitAndAdd(b);
} else {
var y = 10000000000000;
}
var z = ((x < y) ? -1 : ((x > y) ? 1 : 0));
return z;
};
jQuery.fn.dataTableExt.oSort['date-euro-desc'] = function(a, b) {
if (trim(a) != '') {
var x = splitAndAdd(a);
} else {
var x = 10000000000000;
}
if (trim(b) != '') {
var y = splitAndAdd(b);
} else {
var y = 10000000000000;
}
var z = ((x < y) ? 1 : ((x > y) ? -1 : 0));
return z;
};
[/code]
This seems to work, at least in Firefox 3 & 4.
Hope it helps.
TP