Answers.Body: <p>Author of the Google Maps plugin here, I'll do my best to answer this. Although I do suspect that it might be better handled by JavaScript on the front-end.</p>
  <p>Let's break this into two separate parts...</p>
  <h3>Ordered by an Address subfield</h3>
  <p>I don't believe that it's possible to order by an Address subfield. The plugin is not changing the behavior of the <code>orderBy</code> parameter, and I don't believe there is a valid way to target an individual column.</p>
  <pre><code>{# This doesn't work #}
  .orderBy('address.city')
  </code></pre>
  <p>Let me know if you find a way to do this, I'd love to be proven wrong.</p>
  <h3>Grouped by an Address subfield</h3>
  <p>Similarly, you could use the <code>groupBy</code> parameter, but I don't think that would work either.</p>
  <pre><code>{# This also doesn't work #}
  .groupBy('address.country')
  </code></pre>
  <p>Again, let me know if you can find a syntax that works.</p>
  <hr />
  <p><strong>As for an actual solution...</strong> I'd recommend pulling down all of the Address data as-is, displaying it as a normal HTML table, and then use an off-the-shelf JS library to manipulate that data further.</p>
  <p>There are many JS libraries that allow you to sort an HTML table, so I won't bother linking to one here. Your solution will likely rely on whatever JS libraries you are already using.</p>
  <p>I know it's not exactly what you wanted to hear, but I hope that helps!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-13T00:54:04.670Z
Answers.LastActivityDate: 2022-12-13T00:54:04.670Z
Answers.UserDisplayName: Lindsey D
Body: <p>I have a Google Maps plugin <code>address</code> field and I'd like to show a tabular list of locations ordered by an address subfield like <code>address.country</code> or <code>address.city</code>.</p>
  <p>And once I have that list I'd like to group those locations by an address subfield.</p>
  <p>Something similar to this...</p>
  <pre><code>{% set allLocations = craft.entries.section('dealers').orderBy('address.city').all() %}
  {% set allLocationsByCountry = allLocations|group(e =&gt; e.address.country) %}
  </code></pre>
  <p>Any suggestions for how to write the query and group filter?</p>
  
Tags: <plugin-googlemaps>
Title: Google Maps Plugin - Ordering/grouping locations by address subfield
ThreadText: # Google Maps Plugin - Ordering/grouping locations by address subfield
  
  (Asked by: username_0 on 2022-12-12)
  
  I have a Google Maps plugin `address` field and I'd like to show a tabular list of locations ordered by an address subfield like `address.country` or `address.city`.
  
  And once I have that list I'd like to group those locations by an address subfield.
  
  Something similar to this...
  
  ```
  {% set allLocations = craft.entries.section('dealers').orderBy('address.city').all() %}
  {% set allLocationsByCountry = allLocations|group(e => e.address.country) %}
  
  ```
  
  Any suggestions for how to write the query and group filter?
  
  **Tags:** plugin-googlemaps
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-12-13. Score: 1
  
  Author of the Google Maps plugin here, I'll do my best to answer this. Although I do suspect that it might be better handled by JavaScript on the front-end.
  
  Let's break this into two separate parts...
  
  ### Ordered by an Address subfield
  
  I don't believe that it's possible to order by an Address subfield. The plugin is not changing the behavior of the `orderBy` parameter, and I don't believe there is a valid way to target an individual column.
  
  ```
  {# This doesn't work #}
  .orderBy('address.city')
  
  ```
  
  Let me know if you find a way to do this, I'd love to be proven wrong.
  
  ### Grouped by an Address subfield
  
  Similarly, you could use the `groupBy` parameter, but I don't think that would work either.
  
  ```
  {# This also doesn't work #}
  .groupBy('address.country')
  
  ```
  
  Again, let me know if you can find a syntax that works.
  
  ---
  
  **As for an actual solution...** I'd recommend pulling down all of the Address data as-is, displaying it as a normal HTML table, and then use an off-the-shelf JS library to manipulate that data further.
  
  There are many JS libraries that allow you to sort an HTML table, so I won't bother linking to one here. Your solution will likely rely on whatever JS libraries you are already using.
  
  I know it's not exactly what you wanted to hear, but I hope that helps!
  
  
  ---
  
  