1

I am building a timeline which I want to paginate. For this to be efficient, the timeline entries should be in a linear order.

The challenge is that entries before present (BP) have to be in descending order, i.e. going from 10,000 years BP to 1,000 BP, then in ascending order into the present, i.e. 1400 > 1700 > 2000 > 2018.

After discussing this challenge, a colleague recommended adding a minus to the BP entries' title. So now I auto-generate the titles to become

timeline-YYYY (before present)
timeline+YYYY (present)

The target sort order should then be:

timeline-10000
timeline-1000
timeline+1400
timeline+1700
timeline+2000

Unfortunately when I use SuperSort with natural sort order I get

timeline+1400
timeline+1700
timeline+2000
timeline-1000
timeline-10000

I assume this is because SuperSort sorts the titles as strings and follows the ASCII character sort order.

How can I get my target sort order?

3
  • This SQL fiddle gives me exactly what I need, but when I use it with Craft it throws a database exception.
    – Crafty Cat
    Commented Sep 5, 2018 at 8:13
  • Split it up into two queries? i.e. grab all entries with a negative year, sort descending, grab all entries with positive year, sort ascending, then append the results. If you want to go the SQL route, you'll need to write a custom plugin.
    – Brad Bell
    Commented Sep 6, 2018 at 23:15
  • Yes, I think without a separate field holding the year this cannot be done. The SQL fiddle's solution is not possible with Yii as it interprets the replace() function as a list and throws an error. For now I have a checkbox in the UI with which the user preselects the desired interval. Going down the plugin or module route comes later, once I know how.
    – Crafty Cat
    Commented Sep 8, 2018 at 4:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.