Answers.Body: <p>You could wrap this in another for loop and put a condition on the inner fors, </p>
  
  <p>something like</p>
  
  <pre><code>{% for option in myPositionDropdown %}
    &lt;h2&gt;{{ option.value }}&lt;/h2&gt;
  
    {% for position, playersInPosition in playersGrouped if position == option.value %}    
      &lt;ul&gt;
  
      {% for player in playersInPosition %}
        {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
        &lt;li&gt;
          {{ playerData.fullName }}
          {{ playerData.age }}
          ...
        &lt;/li&gt;
      {% endfor %}
  
      &lt;/ul&gt;
    {% endfor %}
  
  {% endfor %}
  </code></pre>
  
  <p>(untested code)</p>
  
  <p>That sort of idea though, loop the dropdown in order and show the grouped results. Heck, you probably don't need to group them at all since you're filtering them out in each loop.</p>
  
  <p>HTH</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-27T08:49:54.960Z
Answers.LastActivityDate: 2019-09-27T08:49:54.960Z
Answers.UserDisplayName: billythekid
Body: <p>Following <a href="https://craftcms.stackexchange.com/questions/9135/group-by-field-in-matrix-field">this topic</a>, I have an additional question.</p>
  
  <p>The results are <strong>not ordered</strong> by the order of the Dropdown Options.
  How can I get this done?</p>
  
  <p><a href="https://i.sstatic.net/Zneuh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Zneuh.png" alt="order"></a></p>
  
  <p>Code:</p>
  
  <pre><code>{% set players = entry.myPlayersMatrix %}
  {% set playersGrouped = players|group('myPositionDropdown.label') %}
  
  {% for position, playersInPosition in playersGrouped %}
      &lt;h2&gt;{{ position }}&lt;/h2&gt;
      &lt;ul&gt;
      {% for player in playersInPosition %}
          {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
          &lt;li&gt;
              {{ playerData.fullName }}
              {{ playerData.age }}
              ...
          &lt;/li&gt;
      {% endfor %}
      &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
Tags: <matrix><order><group><filtering><sort>
Title: Order grouped results by dropdown order
ThreadText: # Order grouped results by dropdown order
  
  (Asked by: username_0 on 2019-09-26)
  
  Following [this topic](https://craftcms.stackexchange.com/questions/9135/group-by-field-in-matrix-field), I have an additional question.
  
  The results are **not ordered** by the order of the Dropdown Options.
  How can I get this done?
  
  [![order](https://i.sstatic.net/Zneuh.png)](https://i.sstatic.net/Zneuh.png)
  
  Code:
  
  ```
  {% set players = entry.myPlayersMatrix %}
  {% set playersGrouped = players|group('myPositionDropdown.label') %}
  
  {% for position, playersInPosition in playersGrouped %}
      <h2>{{ position }}</h2>
      <ul>
      {% for player in playersInPosition %}
          {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
          <li>
              {{ playerData.fullName }}
              {{ playerData.age }}
              ...
          </li>
      {% endfor %}
      </ul>
  {% endfor %}
  
  ```
  
  **Tags:** matrix, order, group, filtering, sort
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-09-27. Score: 1
  
  You could wrap this in another for loop and put a condition on the inner fors,
  
  something like
  
  ```
  {% for option in myPositionDropdown %}
    <h2>{{ option.value }}</h2>
  
    {% for position, playersInPosition in playersGrouped if position == option.value %}    
      <ul>
  
      {% for player in playersInPosition %}
        {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
        <li>
          {{ playerData.fullName }}
          {{ playerData.age }}
          ...
        </li>
      {% endfor %}
  
      </ul>
    {% endfor %}
  
  {% endfor %}
  
  ```
  
  (untested code)
  
  That sort of idea though, loop the dropdown in order and show the grouped results. Heck, you probably don't need to group them at all since you're filtering them out in each loop.
  
  HTH
  
  
  ---
  
  