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

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

harkirat.singhharkirat.singh Posts: 5Questions: 1Answers: 0

Wondering is there is a way to integrate DayJS to use for sorting date columns similar to momentjs?

Answers

  • allanallan Posts: 64,999Questions: 1Answers: 10,760 Site admin

    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

  • harkirat.singhharkirat.singh Posts: 5Questions: 1Answers: 0

    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.

  • allanallan Posts: 64,999Questions: 1Answers: 10,760 Site admin

    I'd be utterly astonished if they changed their API. I'll take a look - thanks for the heads up.

    Allan

  • allanallan Posts: 64,999Questions: 1Answers: 10,760 Site admin

    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

  • harkirat.singhharkirat.singh Posts: 5Questions: 1Answers: 0

    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.

  • kthorngrenkthorngren Posts: 22,249Questions: 26Answers: 5,119

    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 with data to load the data. Similar to this example.

    Kevin

  • harkirat.singhharkirat.singh Posts: 5Questions: 1Answers: 0

    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.

  • allanallan Posts: 64,999Questions: 1Answers: 10,760 Site admin

    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

  • harkirat.singhharkirat.singh Posts: 5Questions: 1Answers: 0

    Thank for you digging into that and getting to the bottom of it.

Sign In or Register to comment.