• Resolved jfbprivate

    (@jfbprivate)


    Hi,

    I’m aware of the various threads regarding the sorting of dates. I couldn’t find anything about this particular issue though—

    My preferred date format is MM/DD/YY(YY), however, in some of my tables I use the full date format, e.g. “January 3, 1997.”

    Is there any way to have TablePress convert the date into something that it understands in terms of sorting as of today?

    Is that something that could be achieved through “DataTables Sorting plugins” or “Change DataTables strings,” or do I have to use hidden columns?

    Apologies in case this has already been asked and solved.

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    You could potentially use the DataTables Sorting plugins Extension – if you add a custom sorting algorithm for this date format to its code. Other than that, I only know the hidden columns method, sorry.

    Regards,
    Tobias

    Thread Starter jfbprivate

    (@jfbprivate)

    So I just created an additional hidden column and translated the date format from “Month Day, Year” (column 2 [1]) to “MM/DD/YYYY” (column 1 [0]).

    I used the following custom command and also set the hidden column to 0% width in the CSS so it won’t affect the table size:

    “columnDefs”: [ { “orderData”: [ 0 ], “targets”: [ 1 ] }, { “visible”: false, “targets”: [ 0 ] } ]

    For whatever reason it results in the sorting algorithm mixing up the years. It only sorts month and day correctly but it seems to ignore the year entirely.

    Here’s an example:

    October 2, 1996
    October 4, 1997
    October 6, 1997
    October 7, 1996

    I can’t figure out what’s causing this. Before trying another date format (YYYY-MM-DD) I wanted to check whether you have an idea what might be the problem here.

    Thanks.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    could you maybe add another command (to force the date type)?:

    "columnDefs": [ { "orderData": [ 0 ], "targets": [ 1 ] }, { "visible": false, "type": "date", "targets": [ 0 ] } ]
    

    Regards,
    Tobias

    Thread Starter jfbprivate

    (@jfbprivate)

    !

    Thank you!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Translating (and Sorting) the Date Format “Month Day, Year”’ is closed to new replies.