Filtering through table data based off of select column

lballard702
Participant

<!-- Pulling the data from the table and assigning it to table -->
{% set people = hubdb_table_rows(2639483, queryparam) %}

 

<!-- This is where I get lost!! My program shows the select options, but will not filter once the user has selected an option from the form -->
<!-- sets the different query parameters using submitted input for hubdb query -->
{% set queryparam = "" %}
{% if request.query_dict.type in ["1", "2", "3", "4"] %}
{% set queryparam = queryparam ~ "&type="~request.query_dict.type|urlencode %}
{% endif %}
{% if request.query_dict.type == "show-all" %}
{% set queryparam = queryparam %}
{% endif %}


<form id="form_id" method="get">
<select name="flavor_options" form="form_id" onChange="this.form.submit()">
<option value="show-all">Show All</option>
<!-- Set flavor options to their values to make search function work -->
{% set flavor_options = hubdb_table_column(2639483, "favorite_ice_cream").options %}
{% for choice in flavor_options %}
{% set flavor_list = flavor_list~choice.id|list%}
{% if choice.id == request.query_dict.flavor_options%} <!-- flavor_options might need to be changed to type -->
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</form>



<!-- If the table is empty return a statement for the user to change their search parameters -->
{% if people == [] %}
<p class='align-center'>Sorry, no people match that criteria. Try changing your filter and search again.</p>

{% else %}
<!-- Loop through each row of data -->
{% for row in people %}

<h2>{{ row.name }} {{row.last_name}}</h2>
<p>Age: {{ row.age }}</p>
<i>
{% for flavor in row.favorite_ice_cream %}
<p>Favorite Ice Cream: {{ flavor.name }}</p>
{% endfor %}
</i>

{% endfor %}
{% endif %}

0 Upvotes
1 Reply 1
sharonlicari
Community Manager

Thank you for sharing @lballard702 


¿Sabías que la Comunidad está disponible en Español?
¡Participa hoy en conversaciones en el idioma de tu preferencia,cambiando el idioma en tus configuraciones!

Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !


0 Upvotes