<p>I did something like this as a workaround:
Loop over entries, fetching all data you need and adding it to an array. Sorting that array with SuperSort and than displaying all info by looping over the array.</p>

<pre><code>{% set tourDates = [] %}
{% set artists = craft.entries.section('artists') %}
{% for artist in artists %}

    {% if artist.tourDates %}
        {% for row in artist.tourDates %}
            {% set tourDates = tourDates|merge([ {
                'tourDate' : row.tourDate|date("d/m/Y")
            } ]) %}
        {% endfor %}
    {% endif %}

{% endfor %}

{% set tourDates = tourDates | supersort('sortAs', '{{ object.tourDate }}') %}

{% for tourDate in tourDates %}
    {{ tourDate.tourDate }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-06-09T12:54:08.367Z
Ah ok, I see where you're going with this. All this is doing at the moment is ordering them based on the day, so 1-31 regardless of what month it is, not the actual date itself. Do you by any chance know how to get it to display the order based on the date?
Amy
CC BY-SA 3.0
2017-06-09T13:43:20.060Z
Maybe with {% tourDates = tourDates | supersort('sortAs', '{{ object.tourDate }}', SORT_LOCALE_STRING) %} ? Or you could write a Twig extension that uses usort() with a custom sort function? https://stackoverflow.com/questions/40462778/how-to-sort-date-array-in-php
Tom De Smet
CC BY-SA 3.0
2017-06-09T12:33:55.707Z
2017-06-09T12:33:55.707Z
Tom De Smet
<p>I used the <a href="https://github.com/aelvan/Preparse-Field-Craft" rel="nofollow noreferrer">preparse plugin</a> to save a date value from a SuperTable field into a static field as 'yyyymmdd'. I could then sort my entries based on that static field.</p>

CC BY-SA 4.0
2018-12-25T14:34:37.200Z
2018-12-25T14:34:37.200Z
Wieger Jelsma
<p>I currently have numerous Super Tables with date fields inside and I am trying to get all table items to list themselves together in date order depending on what the user inputs. I have tried using the Super Sort plugin but haven't had any luck.</p>

<p>Not sure if there is somewhere below where I have gone wrong or misunderstood the documentation. The plugin I am trying to use can be found <a href="https://github.com/TopShelfCraft/SuperSort" rel="nofollow noreferrer">here</a></p>

<p>Does anyone know if this is possible with Super Tables or Matrix fields?</p>

<p>The error I'm currently getting is:</p>

<blockquote>
  <p>Object of class Craft\ElementCriteriaModel could not be converted to string</p>
</blockquote>

<pre><code>protected function doDisplay(array $context, array $blocks = array())   
{
  echo $this-&gt;getAttribute($this-&gt;getAttribute(($context["object"] ?? $this-&gt;getContext($context, "object")), "tourDates", array()), "tourDate", array());
}
</code></pre>

<hr>

<pre><code>if (version_compare(PHP_VERSION, '7', '&gt;=') &amp;&amp; $code === 2 &amp;&amp; 
strpos($message, 'should be compatible with') !== false)
{
    return;
}
parent::handleError($code, $message, $file, $line);
</code></pre>

<hr>

<pre><code>protected function displayWithErrorHandling(array $context, array 
$blocks = array())
{
    try {
        $this-&gt;doDisplay($context, $blocks);
    } catch (Twig_Error $e) {
        if (!$e-&gt;getSourceContext()) {
            $e-&gt;setSourceContext($this-&gt;getSourceContext());
        }
</code></pre>

<p>This is the code I current have:</p>

<pre><code>{% set artists = craft.entries.section('artists') %}
{% set entries = artists | supersort('sortAs', '{ tourDates.tourDate }') %}

{% for entry in entries %}

    {% if entry.tourDates %}
        {% for row in entry.tourDates %}
            {{ row.tourDate|date("d/m/Y") }}
        {% endfor %}
    {% endif %}

{% endfor %}
</code></pre>

<p>I have also tried:</p>

<pre><code>{% set entries = artists | supersort('sortAs', '{ tourDate }') %}
</code></pre>

<p>and </p>

<pre><code>{% set entries = artists | supersort('sortAs', '{{ artists.tourDates.tourDate }}') %}
</code></pre>

CC BY-SA 3.0
2017-06-08T22:05:35.407Z
Never used Super Sort, but can you enabled devMode, then edit the original question and share the full stack trace leading up to that error?
Brad Bell
CC BY-SA 3.0
2017-06-09T07:11:19.780Z
Added the rest of the error :)
Amy
CC BY-SA 3.0
2017-06-09T08:30:38.877Z
Didn't a colleague of you ask this allready in this thread? https://craftcms.stackexchange.com/questions/20720/sorting-supertable-field-with-supersort/20721#20721
Tom De Smet
CC BY-SA 3.0
2017-06-09T09:09:43.503Z
Sadly this solution doesn't solve my issue, as you can see above I have tried all 3 examples shown in the documentation.
Amy
CC BY-SA 3.0
2017-06-09T10:39:27.847Z
What about my comment in that previous thread? Looping over your entries, fetching all data you need and adding it to a new array. Sorting that new array with SuperSort and than displaying all info by looping over the new array.
Tom De Smet
CC BY-SA 3.0
2017-06-09T10:58:42.497Z
I did read your comments, the solution doesn't work for me I'm afraid. If you have an example to show me maybe I have gone wrong somewhere in my loop?
Amy
CC BY-SA 3.0
2017-06-09T12:32:56.100Z
As I can't copy/paste code in a comment with styling applied, I'll add it as an answer.
Tom De Smet
<matrix><order><plugin-supertable><plugin-supersort><sort>
Sort entries by custom date in Matrix field / Super Table
# Sort entries by custom date in Matrix field / Super Table

(Asked by: username_0 on 2017-06-08)

I currently have numerous Super Tables with date fields inside and I am trying to get all table items to list themselves together in date order depending on what the user inputs. I have tried using the Super Sort plugin but haven't had any luck.
Not sure if there is somewhere below where I have gone wrong or misunderstood the documentation. The plugin I am trying to use can be found here
Does anyone know if this is possible with Super Tables or Matrix fields?
The error I'm currently getting is:

Object of class Craft\ElementCriteriaModel could not be converted to string

protected function doDisplay(array $context, array $blocks = array())   
{
  echo $this->getAttribute($this->getAttribute(($context["object"] ?? $this->getContext($context, "object")), "tourDates", array()), "tourDate", array());
}


if (version_compare(PHP_VERSION, '7', '>=') && $code === 2 && 
strpos($message, 'should be compatible with') !== false)
{
    return;
}
parent::handleError($code, $message, $file, $line);


protected function displayWithErrorHandling(array $context, array 
$blocks = array())
{
    try {
        $this->doDisplay($context, $blocks);
    } catch (Twig_Error $e) {
        if (!$e->getSourceContext()) {
            $e->setSourceContext($this->getSourceContext());
        }

This is the code I current have:
{% set artists = craft.entries.section('artists') %}
{% set entries = artists | supersort('sortAs', '{ tourDates.tourDate }') %}

{% for entry in entries %}

    {% if entry.tourDates %}
        {% for row in entry.tourDates %}
            {{ row.tourDate|date("d/m/Y") }}
        {% endfor %}
    {% endif %}

{% endfor %}

I have also tried:
{% set entries = artists | supersort('sortAs', '{ tourDate }') %}

and 
{% set entries = artists | supersort('sortAs', '{{ artists.tourDates.tourDate }}') %}

**Tags:** matrix, order, plugin-supertable, plugin-supersort, sort
> **Comments:**
> **username_1**: Never used Super Sort, but can you enabled devMode, then edit the original question and share the full stack trace leading up to that error?  
> **username_0**: Added the rest of the error :)  
> **username_2**: Didn't a colleague of you ask this allready in this thread? https://craftcms.stackexchange.com/questions/20720/sorting-supertable-field-with-supersort/20721#20721  
> **username_0**: Sadly this solution doesn't solve my issue, as you can see above I have tried all 3 examples shown in the documentation.  
> **username_2**: What about my comment in that previous thread? Looping over your entries, fetching all data you need and adding it to a new array. Sorting that new array with SuperSort and than displaying all info by looping over the new array.  
> **username_0**: I did read your comments, the solution doesn't work for me I'm afraid. If you have an example to show me maybe I have gone wrong somewhere in my loop?  
> **username_2**: As I can't copy/paste code in a comment with styling applied, I'll add it as an answer.  

---

## 2 answers

### Answer by username_2 on 2017-06-09. Score: 2 | Accepted answer

I did something like this as a workaround:
Loop over entries, fetching all data you need and adding it to an array. Sorting that array with SuperSort and than displaying all info by looping over the array.
{% set tourDates = [] %}
{% set artists = craft.entries.section('artists') %}
{% for artist in artists %}

    {% if artist.tourDates %}
        {% for row in artist.tourDates %}
            {% set tourDates = tourDates|merge([ {
                'tourDate' : row.tourDate|date("d/m/Y")
            } ]) %}
        {% endfor %}
    {% endif %}

{% endfor %}

{% set tourDates = tourDates | supersort('sortAs', '{{ object.tourDate }}') %}

{% for tourDate in tourDates %}
    {{ tourDate.tourDate }}
{% endfor %}

> **Comments:**
> **username_0**: Ah ok, I see where you're going with this. All this is doing at the moment is ordering them based on the day, so 1-31 regardless of what month it is, not the actual date itself. Do you by any chance know how to get it to display the order based on the date?  
> **username_2**: Maybe with {% tourDates = tourDates | supersort('sortAs', '{{ object.tourDate }}', SORT_LOCALE_STRING) %} ? Or you could write a Twig extension that uses usort() with a custom sort function? https://stackoverflow.com/questions/40462778/how-to-sort-date-array-in-php  

---

### Answer by username_3 on 2018-12-25. Score: 1

I used the [preparse plugin](https://github.com/aelvan/Preparse-Field-Craft) to save a date value from a SuperTable field into a static field as 'yyyymmdd'. I could then sort my entries based on that static field.


---

