Support » Plugin: TablePress » Sort rows by date with a hidden column

  • Resolved captainchrissy

    (@captainchrissy)


    Hello,
    I have one column where I need to sort the rows by date, but the date is listed as Sep 2017, May 2016, Sep 2016, etc. No day number is listed. I cannot sort correctly by this. It sorts by the month, instead of month/year.

    So I created another column that corresponds to those dates as September 1, 2017, May 1, 2016 etc.

    Is there a way to sort the abbreviated date column based with the data on the full date column, but hide the full date column?

    Thank you

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

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    This is indeed possible. Just add this to the “Custom Commands” text field on the table’s “Edit” screen:

    "columnDefs": [ { "orderData": [ 3 ], "targets": [ 2 ] }, { "visible": false, "targets": [ 3 ] } ]
    

    The 3 stands for the fourth column (with the full dates), the 2 stands for the visible third column (with the abbreviated dates). Note that counting the columns starts with 0 in this code.

    Regards,
    Tobias

    captainchrissy

    (@captainchrissy)

    Thank you Tobias. Do I need to set the column type as a date? We added the code and it’s still sorting column “2 (abbreviated dates)” as Sep 2017, Sep 2016, May 2017, etc.

    I’m wondering if I need to somehow specify that column 3 (full dates) is a date?

    Thank you again

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    normally, you don’t have to set it, as the JS code will try to automatically detect the format. However, you will therefore have to make sure that you are using a date format that is recognized. Can you maybe try mm/dd/yyyy for the format (in all cells of that column!)?

    Regards,
    Tobias

    captainchrissy

    (@captainchrissy)

    Dear Tobias,
    Thank you, the change in date format made it work perfectly. Thank you again.

    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!

    • This reply was modified 6 months, 3 weeks ago by  benchwarmer. Reason: accidental post
    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    oh, I forgot: Other date formats (like dd.mm.yyyy) are possible as well, by using the Extension from https://tablepress.org/extensions/datatables-sorting-plugins/

    Regards,
    Tobias

    • This reply was modified 6 months, 3 weeks ago by  TobiasBg.
    timatthias

    (@timatthias)

    ok thanks, I read and follow your instructions. If I have some more questions, I contact you one more time 🙂

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    sounds good! 🙂

    Best wishes,
    Tobias

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.