Hi @DHolland, you’re not ordering/sorting here, you’re filtering. So:
{% set query = query ~ '&division__contains=Small' %} {# make sure "Small" here matches the value of the multiselect option exactly, it is case sensitive #}
{% set table = hubdb_table_rows(table_id, query) %}
{% for row in table %}
{{row}}
{% endfor %}
Or loop over the table and only display those with division == small
{% set table = hubdb_table_rows(table_id, query) %} {# assuming here you may have other queries #}
{% for row in table %}
{% if row.division == 'small' %} {# filter #}
{{row}}
{% endif %}
{% endfor %}
Thanks @piersg . I actually am interested in sorting not filtering.
I would like all the companies to be provided by HubDB just order them based on the size option of the Division column.
I plan to use a query parameter to cause this ordering. For example pageurl/?sort=small would list all the companies with the ones that have are “small” in the division column shown first.
I feel like javascript might be a preferred tool for this but just wasn’t sure if it was possible on the hubdb side.
Ah ok, sorry for the misunderstanding. It is actually possible with HubL:
{% if request.query_dict.sort == 'small' %}
{% set query = query ~ '&orderBy=-division' %}
{% endif %}
{% set table = hubdb_table_rows(table_id, query) %}
{% for row in table %}
{{row}}
{% endfor %}
The minus before division reverses the order of sorting.
Alternatively, you could do it with css if you’re using flexbox, which might be a bit more flexible as you don’t have to specify a sort order, it’ll just order the items that match the url query parameter to the first position in the flex container for you. And within that ordering they’ll be alphabetical, whereas the above version if you add a sort filter to the for loop it’ll override the orderBy query.
{% set table = hubdb_table_rows(table_id) %}
<div class="flex-container" id="company-wrapper">
{% for row in table|sort(False, False, 'name') %}
<div style="order: {% if row.division|lower == request.query_dict.sort|lower %}1{% else %}2{% endif %}">
{# content #}
</div>
{% endfor %}
</div>