Is it possible to use DayJS for sorting similar to moment.js
Is it possible to use DayJS for sorting similar to moment.js

Wondering is there is a way to integrate DayJS to use for sorting date columns similar to momentjs?
Wondering is there is a way to integrate DayJS to use for sorting date columns similar to momentjs?
Answers
There isn't built in support for DayJS I'm afraid (as there is for Luxon and Moment), but it would be possible to create a plugin to do it. Have a look at the documentation for adding new content types.
If you give it a go, let us know how you get one, I'm sure others would be interested as well.
Allan
Ok thanks. I'll going to switch to using moment. FYI it seems the latest moment version 2.30 does not appear to be compatible with datatables as sorting does not work right. Works fine on 2.29.
I'd be utterly astonished if they changed their API. I'll take a look - thanks for the heads up.
Allan
I've just tried it here and it seems to work no problem.
Can you link to a test case showing the issue please?
Allan
It seems to only happen when loading data via ajax using a server side script. When I get some time ill make up a sample.
If you are using server side processing, ie
serverSide: true
, then the server script is expected to perform the sorting. Sorting won't happen client side.However if you are using client side processing with
ajax
loading then the client side Datatables sorts. For client side it doesn't matter if the data source is ajax, Javascript or HTML. Can you update Allan's test case with an example of the Ajax data being received? Remove the HTML table, use the browser's network inspector to get some example rows and use a Javascript variable along withdata
to load the data. Similar to this example.Kevin
Here is a sample that shows the issue. I managed to re-create it wihout ajax
If you comment out 2.30.1 version of moment in the code and use the 2.29.2 you will see it starts to work properly.
Actually, what you've found is a bug fix in Moment - this one to be specific.
The issue is in the use of "D" in the format and "01" in the date. Either it should be "DD" with "01" or "D" with "1".
It looks like they tightened up their parsing to correct that bug. "DD" will work correctly with that data.
Allan
Thank for you digging into that and getting to the bottom of it.