• Resolved Jimmyfrantic

    (@jimmyfrantic)


    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?

    https://www.ads-software.com/plugins/tablepress/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    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

    Thread Starter Jimmyfrantic

    (@jimmyfrantic)

    Hah! ?? 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*

    Plugin Author Tobias B?thge

    (@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 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sorting a column with a custom date format’ is closed to new replies.