Dynamic Comparison Table

Has anyone ever created a dynamic comparison table similar to Apples?

I’ve tried using the below code, cloning it and tweaking each one by changing any key point from 1 to 2, 3 etc (i.e. showing 3 lists), but I can’t get it to work.

Similar to Apples, at the end of the URL my test page updates with the query for example ?house_type=16 but unlike Apple, I’m unable to figure out how to add to this with the other lists.

Any ideas?

<table class="filter_container"><!-- Table 1 -->
 <tr>
 <td>
 <!-- Filter -->
 <form id="filter1" method="get">
 <select name="house_type" form="filter1" onChange="this.form.submit()">
 <option value="show-all">Show All</option>
 {% set house_types1 = hubdb_table_column(1234567, "house_type").options %}
 {% for choice1 in house_types1 %}
 {% set house_type_list1 = house_type_list1~choice1.id|list %} 
 {% if choice1.id == request.query_dict.house_type %}
 <option selected="selected" value="{{ choice1.id }}">{{ choice1.name }}</option>
 {% else %}
 <option value="{{ choice1.id }}">{{ choice1.name }}</option>
 {% endif %}
 {% endfor %}
 </select>
 </form>
 <!-- Query Parameters -->
 {% set queryparam1 = "" %}
 {% if request.query_dict.house_type 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"] %}
 {% set queryparam1 = queryparam1 ~ "house_type="~request.query_dict.house_type|urlencode %}
 {% endif %}
 {% if request.query_dict.house_type == "show-all" %}
 {% set queryparam1 = queryparam1 ~ "&orderBy=house_type" %}
 {% endif %}
 {% set table1 = hubdb_table_rows(1234567, queryparam1) %}
 {% if table1 == [] %}
 <p class='align-center'>Sorry, no listings found for that Search. Try changing your filter and search again.</p>
 {% else %} 
 {% for row in table1 %} 
 <div class="sitename">
 House Name: {{ row["house_type"].name}} <br>
 Ref: {{ row["house_type_ref"]}}
 </div>
 {% endfor %} 
 {% endif %} 
 </td>
 </tr>
 </table>

Thank you for your post @ben-duchy !

@Teun & @Sjardo Do you have experience with dynamic comparison table? Would you be able to weigh in here?

Hi @ben-duchy and @natsumimori ,

The hubdb_table_rows function uses the same query options as the API.

If you want to pass multiple results, you should switch your column type to ‘multi-select’ and pass it all the values you need. It is not really efficient when you create new house types, but this should work.

Each row would have a option set from the multi-select, which would be in your case the numbers 1 to 28.
Because you want the URL params to be comma separated, you do not have to do any formatting and could change your query to this:

"house_type__in="~request.query_dict.house_type|urlencode

Which should result in something like this:

house_type__in=1%2C8%2C16%2C27

Where %2C is the encoded ,
Give it a try and let me know if this works :slightly_smiling_face:

Hi @ben-duchy,

What @Teun is telling is true. But to switch from the query within the url when having multiple values for one query_dict, you can use this code:

{# Get query_dict #}
{% set cat_field = 'house_type' %}

{# if there is a paramater/filter selected #}
{% if request.query_dict != '' %}
 {% set dict = [] %} {# create array to collect categories #}
 {% for item in request.query|split('&') %} {# split paramaters together with values #}
 {% set currect_dict = item|split('=') %} {# split value from paramater #}
 {% if currect_dict[0] == cat_field %} {# check if it's a cat #}
 {% do dict.append(currect_dict[1]) %} {# add to selected cat array #} 
 {% endif %}
 {% endfor %}
{% endif %}

Thanks for your help. @Indra & @Teun, I will certainly give it a try. :+1:

Hey @ben-duchy , after trying the method Teun and Indra suggested and when your query is resolved, please help us by making them as solutions​:wink: