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

<p>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.</p>

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

<pre><code>timeline-YYYY (before present)
timeline+YYYY (present)
</code></pre>

<p>The target sort order should then be:</p>

<pre><code>timeline-10000
timeline-1000
timeline+1400
timeline+1700
timeline+2000
</code></pre>

<p>Unfortunately when I use SuperSort with natural sort order I get</p>

<pre><code>timeline+1400
timeline+1700
timeline+2000
timeline-1000
timeline-10000
</code></pre>

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

<p>How can I get my target sort order?</p>

CC BY-SA 4.0
2018-09-05T08:13:34.077Z
[This SQL fiddle](http://sqlfiddle.com/#!9/fe0833/11) gives me exactly what I need, but when I use it with Craft it throws a database exception.
Crafty Cat
CC BY-SA 4.0
2018-09-06T23:15:44.803Z
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
CC BY-SA 4.0
2018-09-08T04:17:53.730Z
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
<ordering><plugin-supersort>
How to sort entries of a timeline?
# How to sort entries of a timeline?

(Asked by: username_0 on 2018-09-04)

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?

**Tags:** ordering, plugin-supersort

> **Comments:**
> **username_0**: [This SQL fiddle](http://sqlfiddle.com/#!9/fe0833/11) gives me exactly what I need, but when I use it with Craft it throws a database exception.  
> **username_1**: 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.  
> **username_0**: 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.  

---

## 0 answers

