I have datatables that contain of multiple column of dates. But all the column's date is not work perfectly when sorting asc and desc. Just to inform that all my date is in dd-mm-yyyy format. I am using a function to make it as dd-mm-yyyy.
I have trying to apply this reference but not help. I didn't know whether I am apply in the right way or not, please correct me.
HTML
<table id="projectListTable">
<thead>
<tr>
<th>Project Name</th>
<th>Plan Start</th>
<th>Plan Finish</th>
</tr>
</thead>
</table>
JS
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"extract-date-pre": function(data) {
if (data == null){
return data;
}
else {
new_data = data.split("T");
new_data[0] = displayDate(new_data[0]);
return new_data[0];
}
},
"extract-date-asc": function(a, b) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"extract-date-desc": function(a, b) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
});
$('#projectListTable').DataTable({
columns: [
{ data : "project_name" },
{ data : "project_planned_start",
render: function(data){
if (data == null){
return data;
}
else {
new_data = data.split("T");
new_data[0] = displayDate(new_data[0]);
return new_data[0];
}
}
},
{ data : "project_planned_end",
render: function(data){
if (data == null){
return data;
}
else {
new_data = data.split("T");
new_data[0] = displayDate(new_data[0]);
return new_data[0];
}
}
}
],
columnDefs: [
{
type: 'extract-date',
targets: [1]
},
{
type: 'extract-date',
targets: [2]
}
]
});