Problem with sorting column by datetime
Problem with sorting column by datetime
voloderlejla
Posts: 2Questions: 1Answers: 0
I added in head of html :
and in datatable
order: [[2, "desc"]],
columnDefs: [{ type: 'date-eu', 'targets': [2], orderable: true }], and before initialising datatable
$.fn.dataTable.moment('DD.MM.YYYY HH:mm:ss');
But it doesn't work. What can I do to fix this problem?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
in head I added two scripts :
https://momentjs.com/downloads/moment-with-locales.min.js
https://cdn.datatables.net/plug-ins/1.10.15/dataRender/datetime.js
To use this for sorting you need the two scripts noted in the datetime sorting blog.
Also, it looks like your moment format is wrong. Your date format is
26.1.2021
and your format isDD.MM.YYYY
. Since your dates don't include a leading 0 for the month and day you will need to useD.M.YYYY
instead. Please refer to the moment format docs for a list of all the formats.Kevin