WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] Sort dates by year (8 posts)

  1. montymcmahon
    Member
    Posted 1 year ago #

    We're trying to figure out how to sort dates in this format - MM/DD/YEAR. We've tried a number of supposed solutions, but nothing worked.

    By default, these numbers are sorted by the month. We're using TP as an event calendar, so in that scenario, the 2013 dates get mixed in with the 2014 dates. So 01/01/2014 comes before 02/01/2013 in the sorted results.

    Can you tell us how we can get this working so it sorts by year, then month, then day in the MM/DD/YEAR format?

    http://wordpress.org/extend/plugins/tablepress/

  2. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    thanks for your post, and sorry for the trouble.

    To achieve that, please install this TablePress Extension: http://tablepress.org/extensions/datatables-sorting-plugins/
    That contains a sorting algorithm for the date format that you are using.
    If it doesn't work out of the box, after installing this, we might need a small extra command. To find out how that has to look like, please post the link to the page with the table then.

    Another important thing: For the sort to work correctly, all cells in that Date column need to be dates.

    Regards,
    Tobias

  3. montymcmahon
    Member
    Posted 1 year ago #

    That could be the problem - we tried this extension, but some of the cells in that column were blank or said anytime. That would cause it not to sort properly then?

  4. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    correct, "anytime" is recognized as a string, so that the sorting is thrown off. It might be possible to still force a certain sort type, but for that I'd need to see the table, so that I can tell you the necessary command to achieve this. Can you please post a link?

    Regards,
    Tobias

  5. montymcmahon
    Member
    Posted 1 year ago #

  6. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    thanks for the link!

    The necessary command for this would be

    "aoColumnDefs": [ { "sType": "date", "aTargets": [ 1 ] }, { "sType": "formatted-num", "aTargets": [ 4 ] } ]

    which is actually pretty close to what you already have. Please replace the current content of the "Custom Commands" textfield with that.
    I've also added code to fix the currency sorting in the fifth column to this command. (This is the reason why the Sorting Plugins Extension is necessary. It's not necessary for the date sorting, as you are using MM/DD/YYYY, but only for the currency sorting.)

    Regards,
    Tobias

  7. montymcmahon
    Member
    Posted 1 year ago #

    Looks like we've got it. Thanks!

  8. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    great! :-) Thanks for the confirmation!

    Best wishes,
    Tobias

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic