Sort a column according date in luxon format "dd.MM.yyyy" with data from csv does not work
Sort a column according date in luxon format "dd.MM.yyyy" with data from csv does not work
rootjs
Posts: 3Questions: 1Answers: 0
Link to test case: https://jsfiddle.net/rootjs/4hn13rbz/
Debugger code (debug.datatables.net): n/a
Error messages shown: none
Description of problem: Row "0" should be recognized as luxon date format and should be sorted according this date format. For some reason this doesn't work, it's just sorted in lexicographical order, which is wrong.
This question has an accepted answers - jump to answer
Answers
Since the CSV date format matches the
DataTable.datetime('dd.MM.yyyy');
format you defined you don't need to use the date renderer, for example:However if you want to use the date renderer you need to supply the to, from and locale parameters. By default the renderer looks for an ISO-8601 date which you don't have. You will need this:
See the Date Renderer docs for details.
Updated example:
https://jsfiddle.net/15Lbhaj0/
Kevin
Thanks a lot Kevin! With the additional function parameters for the date renderer / datetime the sorting works
I had a look in the Date Renderer docs again and I think the relation to sorting / correct date format recognition and the number of parameters is not obvious there.
If I get it correctly
DataTable.render.datetime(to)
which I used is only helpful when the table contains ISO-8601 date data and the aim is to format this data to another format.Maybe the documentation:
might be enhanced by a hint like this:
"Use
from
parameter to correctly recognize non ISO-8601 date formats and enable sorting of these formats."Correct.
Good call on the documentation clarification. I've phrased it slightly different, but with the same idea:
I've got it in git and it will be deployed with the next site update.
Thanks!
Allan
Thanks Allan for picking this up. I like the library and how it's maintained