WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] Sorting a column with a custom date format (4 posts)

  1. Jimmyfrantic
    Member
    Posted 7 months ago #

    Hi!

    I've searched in FAQ and Documentation (including DataTables Sorting plugin) and I didn't find a proper way to handle this particular issue.

    The problem is that my client is very demanding and specifically requires the following date format: DD.MM. - DD.MM.YYYY in case of events lasting longer than 1 day and DD.MM.YYYY in case of 1-day events. Unfortunately, sorting goes south, obviously.

    I thought maybe there is a way to sort using different columnn than actually clicked? Specifically, let's make a column with above-mentioned date format and next to it another, hidden, column with YYYY-MM-DD for example. Clicking on the first column's header would actually invoke sorting on the hidden column - is that even possible? This is not an ideal solution, since every new event would require entering both date formats, but it's better than nothing. Sorting on YYYY-MM-DD works flawlessly. Even if we somehow told the Tablepress to sort basing on the first five characters being "DD.MM", it would break at year. 2014 would be among 2013s, etc. It HAS TO (sigh) be sorted by the first (or the only in some cases) day of an event, not the last, and the first day doesn't have a year attached.

    Is there some quirky regex-like way to handle that?

    Does anyone have a solution?

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

  2. TobiasBg
    Member
    Plugin Author

    Posted 7 months ago #

    Hi,

    thanks for your question, and sorry for the trouble.

    In fact, adding another column with the data in sortable format is what I would have suggested here :-)
    It is possible to do this with some "Custom Commands" for the DataTables JS library, specifically:

    "aoColumnDefs": [ { "iDataSort": 4, "aTargets": [ 3 ] }, { "bVisible": false, "aTargets": [ 4 ] } ]

    The numbers there indicate the visible column, the column that shall be sorted upon and the hidden column (attention, counting columns starts with 0).
    In this example, the fourth column would use the data from the fifth column for sorting, and the fifth column would be hidden.

    Regards,
    Tobias

  3. Jimmyfrantic
    Member
    Posted 7 months ago #

    Hah! :D thanks a lot!

    Awesome addon, by the way, saved me countless hours already!

    ...if only I knew about this before, I wouldn't create all these damned data-sheets all by myself...*shivers*

  4. TobiasBg
    Member
    Plugin Author

    Posted 7 months ago #

    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!

Reply

You must log in to post.

About this Plugin

About this Topic