<p>You could loop through all your events, and create a date-keyed hash with the ids of the entries - assuming your  (e.g</p>

<pre><code>    {% set saleDays = {} %}
    {% for entry in events %}
       {% for row in table %}
          {% if attribute(saleDays, row.date|date(mdY)) is defined %}
               {% set saleDays = saleDays|merge({ 
                  (row.date|date(mdY)): attribute(saleDays, row.date|date(mdY)) | merge([entry.id]) 
               }) %}
          {% else %}
               {% set saleDays = saleDays|merge({ (row.date|date(mdY)): [entry.id]})
          {% endif %}
     {% endfor %}
</code></pre>

<p>This would result in a hash, whose keys were dates of ticket sales, and whose values were arrays of entry id's (which could then be queried), or you could set the values inside the array to the entry models themselves.</p>

<p>You would then need to sort this hash to get the dates in order (think you'd need to write a custom extension), and then you could loop through it.</p>

<p>But to be honest, by that point you'd be better off just writing a module and doing the whole thing in php where it'd be easier.</p>

CC BY-SA 4.0
2019-08-06T16:35:13.813Z
2019-08-06T16:35:13.813Z
Nick
<p>The company whose website I'm building host events, and for each of these events, it is only possible to purchase tickets on certain days, but for each event, there can be more than 1 such day.</p>

<p>They want a view which shows:</p>

<h3>Event A</h3>

<ul>
<li>Ticket sale days: day 1, day 2</li>
</ul>

<h3>Event B</h3>

<ul>
<li>Ticket sale days: day 1</li>
</ul>

<h3>Event C</h3>

<ul>
<li>Ticket sale days: day 2</li>
</ul>

<p>And another view which shows:</p>

<h3>Ticket sale day 1</h3>

<ul>
<li>Event A</li>
<li>Event B</li>
</ul>

<h3>Ticket sale day 2</h3>

<ul>
<li>Event A</li>
<li>Event C</li>
</ul>

<p>I'm currently using a single-column table field for the ticket sale days which allows me to add as many dates as I wish. With this, I can implement the first view above really easily by looping over the rows in the table.</p>

<p>However, the second view has me stumped since I am unable to group the entries by the rows in the table field. Note that I want to keep this data within a single 'events' section.</p>

<field><table-field><group>
List elements grouped by multiple dates
# List elements grouped by multiple dates

(Asked by: username_0 on 2019-07-26)

The company whose website I'm building host events, and for each of these events, it is only possible to purchase tickets on certain days, but for each event, there can be more than 1 such day.

They want a view which shows:

### Event A

* Ticket sale days: day 1, day 2

### Event B

* Ticket sale days: day 1

### Event C

* Ticket sale days: day 2

And another view which shows:

### Ticket sale day 1

* Event A
* Event B

### Ticket sale day 2

* Event A
* Event C

I'm currently using a single-column table field for the ticket sale days which allows me to add as many dates as I wish. With this, I can implement the first view above really easily by looping over the rows in the table.

However, the second view has me stumped since I am unable to group the entries by the rows in the table field. Note that I want to keep this data within a single 'events' section.

**Tags:** field, table-field, group


---

## 1 answers

### Answer by username_1 on 2019-08-06. Score: 1

You could loop through all your events, and create a date-keyed hash with the ids of the entries - assuming your  (e.g
    {% set saleDays = {} %}
    {% for entry in events %}
       {% for row in table %}
          {% if attribute(saleDays, row.date|date(mdY)) is defined %}
               {% set saleDays = saleDays|merge({ 
                  (row.date|date(mdY)): attribute(saleDays, row.date|date(mdY)) | merge([entry.id]) 
               }) %}
          {% else %}
               {% set saleDays = saleDays|merge({ (row.date|date(mdY)): [entry.id]})
          {% endif %}
     {% endfor %}

This would result in a hash, whose keys were dates of ticket sales, and whose values were arrays of entry id's (which could then be queried), or you could set the values inside the array to the entry models themselves.
You would then need to sort this hash to get the dates in order (think you'd need to write a custom extension), and then you could loop through it.
But to be honest, by that point you'd be better off just writing a module and doing the whole thing in php where it'd be easier.


---

