CMS Development

Woodsy
Top Contributor

Filtering HubDB Multiselect

Hi all, I have set up a filter that pulls data from a Hubdb with a 'select' column type.
{% if request.query_dict.type in ["1", "2", "3", "4","5", "6", "7", "8", "9", "10"] %}

 

My question is how do I do a similar thing with a 'multiselect' column type? (edited)

 

Thanks

0 Upvotes
6 Replies 6
stabuenca
Participant | Partner
Participant | Partner

Filtering HubDB Multiselect

You have an easy solution if you add this sufix to your variable: __contains

piersg
Key Advisor

Filtering HubDB Multiselect

Hey @stabuenca, given the example above, where would the __contains go?

 

*EDIT*

 

No worries, I got it.

 

{% set areaquery = areaquery ~ "&focus_area="~request.query_dict.area|urlencode %}

becomes

{% set areaquery = areaquery ~ "&focus_area__contains="~request.query_dict.area|urlencode %}

 

0 Upvotes
roisinkirby
HubSpot Product Team
HubSpot Product Team

Filtering HubDB Multiselect

Hi @Woodsy could you please share a link to the page you are working on?

0 Upvotes
Woodsy
Top Contributor

Filtering HubDB Multiselect

Hi @roisinkirby I need to replace the second filter query so that the second filter dropdown only returns Hubdb entries that contain that Hubdb multi-select tag.
Here is my current code:

 

    <form id="form_id" method="get">

      <div>
        <h4>Filter by resource type: </h4>
        <select name="type" form="form_id" onChange="this.form.submit()">
          <option value="show-all">Show All</option>
          {% set types = hubdb_table_column(848813, "resource_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 }}" onclick="resourceFilter()">{{ choice.name }}</option>
          {% else %}
          <option value="{{ choice.id }}">{{ choice.name }}</option>
          {% endif %}
          {% endfor %}
        </select>
      </div>
      
      <div>
        <h4>Filter by topic area: </h4>
        <select name="area" form="form_id" onChange="this.form.submit()">
          <option value="show-all">Show All</option>
          {% set areas = hubdb_table_column(848813, "focus_area").options %}
          {% for choice in areas %}
          {% set area_list = area_list~choice.id|list%}
          {% if choice.id == request.query_dict.area%}
          <option selected="selected" value="{{ choice.id }}" onclick="resourceFilter()">{{ choice.name }}</option>
          {% else %}
          <option value="{{ choice.id }}">{{ choice.name }}</option>
          {% endif %}
          {% endfor %}
        </select>
      </div>
      

      
    </form>
  </div>
  


{% set queryparam = "&orderBy=resource_order"~"&resource_order__gt=0" %}
{% if request.query_dict.type in ["1", "2", "3", "4","5", "6", "7", "8", "9", "10"] %}
    {% set queryparam = queryparam ~ "&resource_type="~request.query_dict.type|urlencode %}
{% endif %}
{% if request.query_dict.type == "show-all" %}
    {% set queryparam = queryparam %}
{% endif %}
  
 <!-- Multi-select hubdb query -->
{% set areaquery = "&orderBy=resource_order"~"&resource_order__gt=0" %}
{% if request.query_dict.area in ["1", "2", "3", "4","5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"] %}
    {% set areaquery = areaquery ~ "&focus_area="~request.query_dict.area|urlencode %}
{% endif %}
{% if request.query_dict.area == "show-all" %}
    {% set areaquery = areaquery %}
{% endif %}

 

0 Upvotes
roisinkirby
HubSpot Product Team
HubSpot Product Team

Filtering HubDB Multiselect

Thanks for sharing @Woodsy@tjoyce is this something you could lend your expertise to? Thanks!

0 Upvotes
Woodsy
Top Contributor

Filtering HubDB Multiselect

Hi @roisinkirby did you have any ideas around how I could tackle multi-select HubDB filtering?

 

Thanks