I have a date in the first column of the datatable, and I need it to be sortable as date. The problem is that when I format it as dd/mm/yyyy then the column sort as a string and dont take into account the month, it sorts just by day that is the first character in the string.
Then the data in the table may appears as:
05-11-2019
09-10-2019
11-10-2019
21-09-2019
And is not correct.
The code I use to format is as dd/mm/yyyy, is this:
JS
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [day, month, year].join('-');
}
And the code to append it in the table is this one:
JS
$tblRow.append('<td style="text-align: center;" id="td' + i + '">' + formatDate(ordersList[i][4]) + '</td>');
How can I format it as dd/mm/yyyy and that it can be sortable by day and month.