<p><a href="https://docs.craftcms.com/v3/dev/element-queries/entry-queries.html#orderby" rel="nofollow noreferrer">orderBy()</a> should do the trick.
The docs show following syntax: <code>.orderBy('elements.dateCreated asc')</code></p>

<p>Maybe something like:</p>

<pre><code>{% set entriesList = craft.entries.section('parks')
   .relatedTo(entry.Line.one())
   .orderBy('elements.tableName.row(n).columnName asc')
   .all
%}
</code></pre>

CC BY-SA 4.0
2018-12-10T12:16:55.720Z
Nope. Just a Error. :/
Markus
CC BY-SA 4.0
2018-12-10T13:35:36.433Z
Have you replaced tableName, n and columName with your specific details? Maybe use [] instaed of () for the row "elements.tableName.row[n].columnName"?
phaetons
CC BY-SA 4.0
2018-12-10T13:43:24.510Z
Another possible solution: .orderBy('elements.tableFieldName[n] asc') where n = row number
phaetons
CC BY-SA 4.0
2018-12-10T14:35:01.987Z
tableName and columnName - Yes but what is the n for? I thought near.
Markus
CC BY-SA 4.0
2018-12-10T14:39:15.043Z
.orderBy('elements.parkInfo.row(n).person asc')
Markus
CC BY-SA 4.0
2018-12-10T14:47:12.997Z
here is the error i get Error Info: Array
(
    [0] => 42000
    [1] => 1064
    [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`personen`) `subquery`
INNER JOIN `entries` `entries` ON `entries`.`id` = `subq' at line 13
)
Markus
CC BY-SA 4.0
2018-12-10T15:30:16.957Z
n = row number. You have "person" in the orderBy statement but "personen" in the error. Anyway, ist is possible that "row" didn't work. Did you test my second suggestion?
phaetons
CC BY-SA 4.0
2018-12-10T15:46:25.687Z
Yes i tried both. I found a solution with the supersort Plug-In and ('natsort') option for the Title - because the Title has the same Number too. Not the best Method i think but it work. Anyway, thanks for the help.
Markus
CC BY-SA 4.0
2018-12-10T11:49:05.283Z
2018-12-10T11:49:05.283Z
phaetons
<pre><code>% set entriesList = craft.entries.section('parks').relatedTo(entry.Line.one()).all %}
    {% if entriesList|length %}
    &lt;div id="found-in" class="park"&gt;
        &lt;ul&gt;
            {% for entry in entriesList %}
            &lt;li&gt;&lt;a class="underline" href="{{entry.url}}"&gt;{{entry.title}}&lt;/a&gt;&lt;/li&gt;
            {% endfor %}
        &lt;/ul&gt;
    &lt;/div&gt;
    {% endif %}
</code></pre>

<p>Every Element has a Table where a Number is set
I want to order it by the Number. How can i do it? </p>

<p>Thanks</p>

<craft3><relations><table-field>
order by Table Number Field
# order by Table Number Field

(Asked by: username_0 on 2018-12-10)

% set entriesList = craft.entries.section('parks').relatedTo(entry.Line.one()).all %}
    {% if entriesList|length %}
    
        
            {% for entry in entriesList %}
            {{entry.title}}
            {% endfor %}
        
    
    {% endif %}

Every Element has a Table where a Number is set
I want to order it by the Number. How can i do it? 
Thanks

**Tags:** craft3, relations, table-field


---

## 1 answers

### Answer by username_1 on 2018-12-10. Score: 1

orderBy() should do the trick.
The docs show following syntax: .orderBy('elements.dateCreated asc')
Maybe something like:
{% set entriesList = craft.entries.section('parks')
   .relatedTo(entry.Line.one())
   .orderBy('elements.tableName.row(n).columnName asc')
   .all
%}

> **Comments:**
> **username_0**: Nope. Just a Error. :/  
> **username_1**: Have you replaced tableName, n and columName with your specific details? Maybe use [] instaed of () for the row "elements.tableName.row[n].columnName"?  
> **username_1**: Another possible solution: .orderBy('elements.tableFieldName[n] asc') where n = row number  
> **username_0**: tableName and columnName - Yes but what is the n for? I thought near.  
> **username_0**: .orderBy('elements.parkInfo.row(n).person asc')  
> **username_0**: here is the error i get Error Info: Array (     [0] => 42000     [1] => 1064     [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`personen`) `subquery` INNER JOIN `entries` `entries` ON `entries`.`id` = `subq' at line 13 )  
> **username_1**: n = row number. You have "person" in the orderBy statement but "personen" in the error. Anyway, ist is possible that "row" didn't work. Did you test my second suggestion?  
> **username_0**: Yes i tried both. I found a solution with the supersort Plug-In and ('natsort') option for the Title - because the Title has the same Number too. Not the best Method i think but it work. Anyway, thanks for the help.  

---

