# HubDB: Filter by state alphabetically

**URL:** <https://community.hubspot.com/t/hubdb-filter-by-state-alphabetically/66991>\
**Category:** CMS Development\
**Tags:** design-manager, hubdb, local-development, html\
**Created:** [October 12, 2022, 8:29pm UTC](https://community.hubspot.com/t/hubdb-filter-by-state-alphabetically/66991 "2022-10-12T20:29:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unicorndev](https://avatars.discourse-cdn.com/v4/letter/u/919ad9/32.png) [@unicorndev](https://community.hubspot.com/u/unicorndev)\
**Post date:** [October 12, 2022, 8:29pm UTC](https://community.hubspot.com/t/hubdb-filter-by-state-alphabetically/66991/1 "2022-10-12T20:29:52Z")

</div>

Hello there! I want to be able to have my states listed Alphabetically. Since there is no drag and drop feature on HubDB table, I would have to filter and code it out myself…  
Here is my filter code:

```lia-code-sample
{% set queryparam = "" %}
{% if request.query_dict.state in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"] and request.query_dict.name == "" %}
 {% set queryparam = queryparam ~ "&state=__contains"~request.query_dict.state|urlencode %}

{% endif %}

{% if request.query_dict.state in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"] and request.query_dict.name != "" %}
 {% set queryparam = queryparam~"&state="~request.query_dict.state|urlencode~"&zip__icontains="~request.query_dict.zip|urlencode %}
{% endif %}
{% if request.query_dict.state == "show-all" and request.query_dict.name != "" %}
{% endif %}

```

Here is the code to render data:

```lia-code-sample
<!-- Check if table exists, set sort by state -->
{% if table == [] %}
 <p class='align-center'>Sorry, no listings found for that search. Try changing your filter and search again.</p>
{% else %}
 {% for row in table|sort(False, False, 'state') %}

<div class="consultant-listing">
 <h4>{{ row["name"] }}</h4>

 <div class="information">

{% for state in row.state %}
<div class="fac_state">{{state.name }}
</div>
{% endfor %} 

 <div class="fac_city"">{{ row["city"] }} , {{ row["zip"] }}</div> 
 <div class='location_details'> Locations: {{row["location"]}}</div> 
 <div><i class="fas fa-phone"></i> {{ row["phone"] }}</div>
<br><div class="links"> <i class="fas fa-link"></i> <a href="{{row["website"]}}">Website</a> 
 <br><i class="fas fa-envelope"></i> <a href="mailto:{{ row["email"] }}">{{ row["email"] }}</a>
 </div> 
 {#<div class="location_details">{{ row["location_details"] }}</div>#} 

 </div>
 </div>
 {% endfor %}
 {% endif %}</div>

```

This is the page. I want the states to be in alphabetical order:

 ![Screen Shot 2022-10-12 at 4.28.23 PM.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/4/d43996397709fd72800bc8f25a6e6c00dc957513.jpeg)

Thank you so much 🙂

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [October 13, 2022, 9:12am UTC](https://community.hubspot.com/t/hubdb-filter-by-state-alphabetically/66991/2 "2022-10-13T09:12:27Z")

</div>

Hey [@](https://community.hubspot.com/t5/user/viewprofilepage/user-id/379041)[unicorndev](https://community.hubspot.com/t5/user/viewprofilepage/user-id/388114)

No, it is not possible here as Sorting is generally available in beta version for more details look at this below link-

[https://community.hubspot.com/t5/HubSpot-Ideas/HubDB-rearrange-order/idi-p/5167](https://community.hubspot.com/t5/HubSpot-Ideas/HubDB-rearrange-order/idi-p/5167)

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

---

<div class="post-metadata">

**Author:** ![unicorndev](https://avatars.discourse-cdn.com/v4/letter/u/919ad9/32.png) [@unicorndev](https://community.hubspot.com/u/unicorndev)\
**Post date:** [October 13, 2022, 7:13pm UTC](https://community.hubspot.com/t/hubdb-filter-by-state-alphabetically/66991/3 "2022-10-13T19:13:50Z")

</div>

Yeah, I saw that which is unfortunate. So there is no code to sort this alphabetically?

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [October 13, 2022, 8:25pm UTC](https://community.hubspot.com/t/hubdb-filter-by-state-alphabetically/66991/4 "2022-10-13T20:25:49Z")

</div>

Hi @unicorndev,

first of all - **it is possible to sort your results alphabetically without the beta.**

The magic can be done with the **orderBy** parameter. You can find the available parameters in the [API docs](https://legacydocs.hubspot.com/docs/methods/hubdb/v2/get_table_rows) which the HubL filter query employs.

I created a Hubdb table that includes a column with a name state which I used for my ordering.

```lia-code-sample
{% set states = hubdb_table_rows(5412942, "orderBy=state" ) %}
<ul>
{% for state in states %}
 <li>
 {{state.state}} 
 </li>
{% endfor %}
</ul>

```

screengrab of the output and the table

 ![CleanShot 2022-10-13 at 15.48.25.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/3/d3967baf4c98a6ecdb2622b113330bb29d32f291.png)

hope that helps

best,

Anton

---

<div class="post-metadata">

**Author:** ![unicorndev](https://avatars.discourse-cdn.com/v4/letter/u/919ad9/32.png) [@unicorndev](https://community.hubspot.com/u/unicorndev)\
**Post date:** [October 14, 2022, 3:00pm UTC](https://community.hubspot.com/t/hubdb-filter-by-state-alphabetically/66991/5 "2022-10-14T15:00:02Z")

</div>

Thank you, I believe I’m getting closer to the answer. 🙂  
When I added in the code, it turned out like this:

 ![Screen Shot 2022-10-14 at 10.58.40 AM.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/4/e/4eeecde533908e5938d82447a6b414c1f585eca8.jpeg)

How do I extract the states that way? I tried {{row.state}} but it didn’t work
