I’ve started a HubDB template based on How To Build a Real Estate Listing.
I’ve got the filter to work from a multi select column. All of that is working perfectly.
My question is : after the dropdown filter is applied, how can I filter those results to get different sections of results?
So if “category 1” is selected from the dropdown filter. (and category 1 has some rows where the “color” column has a value of “red”, and some rows where the “color” column has a value of “green.”)
How can I loop through the “Category 1” results and print a headline for each color and then the rows for each color.
ie.
<h2>Red</h2>
{all the rows where the color column = red}
<h2>Green</h2>
{all the rows where the color column = green}
Here is the current code.
<!-- set the filter by drop down -->
<div>
<form id="form_id" method="get">
<div>
<h4>FILTER BY BUILDING TYPE: </h4>
<select name="type" form="form_id" onChange="this.form.submit()">
<option value="show-all">Show All</option>
{% set types = hubdb_table_column(1040830, "building_type").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list%}
{% if choice.id == request.query_dict.type%}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
{{ choice.name }}
</select>
</div>
</form>
</div>
<!-- sets the different query parameters using submitted input for hubdb query -->
{% set queryparam = "" %}
{% if request.query_dict.type in ["1", "2", "3", "4", "5", "6", "7", "8", "9"] %}
{% set queryparam = queryparam ~ "&building_type__contains="~request.query_dict.type|urlencode %}
{% endif %}
{% if request.query_dict.type == "show-all" %}
{% set queryparam = queryparam %}
{% endif %}
<!-- The Table -->
{% set table = hubdb_table_rows(1040830, queryparam) %}
{% 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 %}
<div style="text-align:left; border-bottom: 1px solid #ccc; padding: 20px;">
{{ row.itemname }}<br>
<div style="font-size:10px;">
Cat: {{ row.category }}<br>
Sub: {{ row.subcategory }}<br>
{{ row.building_type }}
</div>
</div>
{% endfor %}
{% endif %}