<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Managing Multiple Filters in HubDB in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Managing-Multiple-Filters-in-HubDB/m-p/427329#M22416</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I might be overthinking/overlooking here, but I have 4 filters I'm using to filter my HubDB table. Country, Region, Partner Type, and Partner Tier.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;It seems very excessive to create a query for every possible combination of filters a user could selected using these filters.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;For example, a query for all filters selected, a query for only the Country and Region selected, a query for only the Country and Partner Type selected, a query for only the Partner Type, Country and Region selected, and so on.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Is there a concise way to handle this?&lt;BR /&gt;&lt;BR /&gt;For reference, here's what I started to do and relized how excessive this could turn out.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!-- ##############################
Query Variables
############################## --&amp;gt;

{% set queryparam = "" %}

&amp;lt;!-- ##############################
Partner Type Variables
############################## --&amp;gt;

{% set partnerType = request.query_dict.partner_type in ["1", "2", "3", "4"] %}
{% set showAllPartnerType = request.query_dict.partner_type == "show-all" %}
{% set partnerTypeQuery = queryparam ~ "&amp;amp;partner_type="~request.query_dict.partner_type|urlencode %}

&amp;lt;!-- ##############################
Country/Multi-Select Variables
############################## --&amp;gt;

{% set country = request.query_dict.partner_country in ["1", "2", "3", "4", "5"] %}
{% set showAllCountry = request.query_dict.partner_country == "show-all" %}
{% set partnerCountryQuery = queryparam ~ "&amp;amp;partner_country__in="~request.query_dict.partner_country|urlencode %}

&amp;lt;!-- ##############################
Partner Region Variables
############################## --&amp;gt;

{% set region = request.query_dict.partner_region in ["1", "2", "3"] %}
{% set showAllRegion = request.query_dict.partner_region == "show-all" %}
{% set partnerRegionQuery = queryparam ~ "&amp;amp;partner_region="~request.query_dict.partner_region|urlencode  %}

&amp;lt;!-- ##############################
Partner Tier Variables
############################## --&amp;gt;

{% set tier = request.query_dict.partner_tier in ["1", "2"] %}
{% set showAllTier = request.query_dict.partner_tier == "show-all" %}
{% set partnerTierQuery = queryparam ~ "&amp;amp;partner_tier="~request.query_dict.partner_tier|urlencode  %}

&amp;lt;!-- ##############################
Filter Queries
############################## --&amp;gt;
&amp;lt;!-- Partner Type Only --&amp;gt;

{% if partnerType %}
    {% set queryparam = partnerTypeQuery %}
{% endif %}

&amp;lt;!-- Region Only --&amp;gt;
{% if region %}
    {% set queryparam = partnerRegionQuery %}
{% endif %}

&amp;lt;!-- Tier Only --&amp;gt;
{% if tier %}
    {% set queryparam = partnerTierQuery %}
{% endif %}

&amp;lt;!-- Country Only --&amp;gt;
{% if country %}
    {% set queryparam = partnerCountryQuery %}
{% endif %}


&amp;lt;!-- Partner Type + Partner Region --&amp;gt;
{% if partnerType and region %}
    {% set queryparam = queryparam ~ partnerTypeQuery~partnerRegionQuery %}
{% endif %}

&amp;lt;!-- Partner Type + Partner Tier --&amp;gt;
{% if partnerType and tier %}
    {% set queryparam = queryparam ~ partnerTypeQuery~partnerTierQuery %}
{% endif %}

&amp;lt;!-- Partner Type + Partner Country --&amp;gt;
{% if partnerType and country %}
    {% set queryparam = queryparam ~ partnerTypeQuery~partnerCountryQuery %}
{% endif %}

&amp;lt;!-- Partner Region + Partner Tier --&amp;gt;
{% if region and tier %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerTierQuery %}
{% endif %}

&amp;lt;!-- Partner Region + Partner Country --&amp;gt;
{% if region and country %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerCountryQuery %}
{% endif %}

&amp;lt;!-- Partner Tier + Partner Country --&amp;gt;
{% if tier and country %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerCountryQuery %}
{% endif %}

&amp;lt;!-- Partner Region + Partner Tier + Partner Type --&amp;gt;
{% if region and tier and partnerType %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerTierQuery~partnerTypeQuery %}
{% endif %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I thought I might be able to get away with this but it doesn't retrun anything:&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% if region or tier or partnerType or country %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerTierQuery~partnerTypeQuery~partnerCountryQuery %}
{% endif %}&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Apr 2021 14:10:14 GMT</pubDate>
    <dc:creator>ckingg</dc:creator>
    <dc:date>2021-04-13T14:10:14Z</dc:date>
    <item>
      <title>Managing Multiple Filters in HubDB</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Managing-Multiple-Filters-in-HubDB/m-p/427329#M22416</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I might be overthinking/overlooking here, but I have 4 filters I'm using to filter my HubDB table. Country, Region, Partner Type, and Partner Tier.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;It seems very excessive to create a query for every possible combination of filters a user could selected using these filters.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;For example, a query for all filters selected, a query for only the Country and Region selected, a query for only the Country and Partner Type selected, a query for only the Partner Type, Country and Region selected, and so on.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Is there a concise way to handle this?&lt;BR /&gt;&lt;BR /&gt;For reference, here's what I started to do and relized how excessive this could turn out.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!-- ##############################
Query Variables
############################## --&amp;gt;

{% set queryparam = "" %}

&amp;lt;!-- ##############################
Partner Type Variables
############################## --&amp;gt;

{% set partnerType = request.query_dict.partner_type in ["1", "2", "3", "4"] %}
{% set showAllPartnerType = request.query_dict.partner_type == "show-all" %}
{% set partnerTypeQuery = queryparam ~ "&amp;amp;partner_type="~request.query_dict.partner_type|urlencode %}

&amp;lt;!-- ##############################
Country/Multi-Select Variables
############################## --&amp;gt;

{% set country = request.query_dict.partner_country in ["1", "2", "3", "4", "5"] %}
{% set showAllCountry = request.query_dict.partner_country == "show-all" %}
{% set partnerCountryQuery = queryparam ~ "&amp;amp;partner_country__in="~request.query_dict.partner_country|urlencode %}

&amp;lt;!-- ##############################
Partner Region Variables
############################## --&amp;gt;

{% set region = request.query_dict.partner_region in ["1", "2", "3"] %}
{% set showAllRegion = request.query_dict.partner_region == "show-all" %}
{% set partnerRegionQuery = queryparam ~ "&amp;amp;partner_region="~request.query_dict.partner_region|urlencode  %}

&amp;lt;!-- ##############################
Partner Tier Variables
############################## --&amp;gt;

{% set tier = request.query_dict.partner_tier in ["1", "2"] %}
{% set showAllTier = request.query_dict.partner_tier == "show-all" %}
{% set partnerTierQuery = queryparam ~ "&amp;amp;partner_tier="~request.query_dict.partner_tier|urlencode  %}

&amp;lt;!-- ##############################
Filter Queries
############################## --&amp;gt;
&amp;lt;!-- Partner Type Only --&amp;gt;

{% if partnerType %}
    {% set queryparam = partnerTypeQuery %}
{% endif %}

&amp;lt;!-- Region Only --&amp;gt;
{% if region %}
    {% set queryparam = partnerRegionQuery %}
{% endif %}

&amp;lt;!-- Tier Only --&amp;gt;
{% if tier %}
    {% set queryparam = partnerTierQuery %}
{% endif %}

&amp;lt;!-- Country Only --&amp;gt;
{% if country %}
    {% set queryparam = partnerCountryQuery %}
{% endif %}


&amp;lt;!-- Partner Type + Partner Region --&amp;gt;
{% if partnerType and region %}
    {% set queryparam = queryparam ~ partnerTypeQuery~partnerRegionQuery %}
{% endif %}

&amp;lt;!-- Partner Type + Partner Tier --&amp;gt;
{% if partnerType and tier %}
    {% set queryparam = queryparam ~ partnerTypeQuery~partnerTierQuery %}
{% endif %}

&amp;lt;!-- Partner Type + Partner Country --&amp;gt;
{% if partnerType and country %}
    {% set queryparam = queryparam ~ partnerTypeQuery~partnerCountryQuery %}
{% endif %}

&amp;lt;!-- Partner Region + Partner Tier --&amp;gt;
{% if region and tier %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerTierQuery %}
{% endif %}

&amp;lt;!-- Partner Region + Partner Country --&amp;gt;
{% if region and country %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerCountryQuery %}
{% endif %}

&amp;lt;!-- Partner Tier + Partner Country --&amp;gt;
{% if tier and country %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerCountryQuery %}
{% endif %}

&amp;lt;!-- Partner Region + Partner Tier + Partner Type --&amp;gt;
{% if region and tier and partnerType %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerTierQuery~partnerTypeQuery %}
{% endif %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I thought I might be able to get away with this but it doesn't retrun anything:&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% if region or tier or partnerType or country %}
    {% set queryparam = queryparam ~ partnerRegionQuery~partnerTierQuery~partnerTypeQuery~partnerCountryQuery %}
{% endif %}&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 14:10:14 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Managing-Multiple-Filters-in-HubDB/m-p/427329#M22416</guid>
      <dc:creator>ckingg</dc:creator>
      <dc:date>2021-04-13T14:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Managing Multiple Filters in HubDB</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Managing-Multiple-Filters-in-HubDB/m-p/427500#M22438</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/17186"&gt;@Anton&lt;/a&gt; , &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/91608"&gt;@alyssamwilie&lt;/a&gt; , do you have some ideas for &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/170856"&gt;@ckingg&lt;/a&gt; ? &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 18:42:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Managing-Multiple-Filters-in-HubDB/m-p/427500#M22438</guid>
      <dc:creator>dennisedson</dc:creator>
      <dc:date>2021-04-13T18:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Managing Multiple Filters in HubDB</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Managing-Multiple-Filters-in-HubDB/m-p/427505#M22439</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/13982"&gt;@dennisedson&lt;/a&gt;&amp;nbsp;thanks for the bump here. I think I got this sorted out with some help from the HubSpot Slack Room&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Here's the code in case any one else is having trouble. This also allows for filtering with checkboxes.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set hubdb_id = YOUR TABLE ID %}
{% if request.query_dict.partner_country != '' %}
  {% set selected_countries = [] %}
  {% for item in request.query|split('&amp;amp;') %}
    {% set keyValue = item|split('=') %}
    {% if keyValue[0] == 'partner_country' %}
      {% do selected_countries.append(keyValue[1]) %}
    {% endif %}
  {% endfor %}
{% endif %}


    &amp;lt;div style="text-align: center; margin:0 auto;"&amp;gt;
        &amp;lt;form id="form_id" method="get"&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;h4&amp;gt;Partner Country&amp;lt;/h4&amp;gt;
              {% set countries = hubdb_table_column(hubdb_id, "partner_country").options %}
              {% for choice in countries %}
                {% if choice.id in selected_countries %}
                  &amp;lt;input type="checkbox" id="{{ choice.id }}" name="partner_country" value="{{ choice.id }}" onChange="this.form.submit()" checked&amp;gt;
                  &amp;lt;label for="{{ choice.name }}"&amp;gt;  {{ choice.name }}&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
                {% else %}
                  &amp;lt;input type="checkbox" id="{{ choice.id }}" name="partner_country" value="{{ choice.id }}" onChange="this.form.submit()"&amp;gt;
                  &amp;lt;label for="{{ choice.name }}"&amp;gt;  {{ choice.name }}&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
                {% endif %}
              {% endfor %}
          &amp;lt;/div&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;h4&amp;gt; Partner Region&amp;lt;/h4&amp;gt;
            &amp;lt;select name="partner_region" form="form_id" onChange="this.form.submit()"&amp;gt;
              &amp;lt;option value="" disabled&amp;gt;- Partner Region -&amp;lt;/option&amp;gt;
              &amp;lt;option value="show-all-destinations" {{ 'selected="selected"' if request.query_dict.partner_region == 'show-all-regions' }} &amp;gt;Show All&amp;lt;/option&amp;gt;
              {% set regions = hubdb_table_column(hubdb_id, "partner_region").options %}
              {% for choice in regions %}
                {% set region_list =region_list~choice.id|list %}
                {% if choice.id == request.query_dict.partner_region %}
                  &amp;lt;option selected="selected" value="{{ choice.id }}"&amp;gt;{{ choice.name }}&amp;lt;/option&amp;gt;
                {% else %}
              &amp;lt;option value="{{ choice.id }}"&amp;gt;{{ choice.name }}&amp;lt;/option&amp;gt;
              {% endif %}
              {% endfor %}
            &amp;lt;/select&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;h4&amp;gt;Partner Type&amp;lt;/h4&amp;gt;
            &amp;lt;select name="partner_type" form="form_id" onChange="this.form.submit()"&amp;gt;
              &amp;lt;option value="" disabled&amp;gt;- Partner Type -&amp;lt;/option&amp;gt;
              &amp;lt;option value="show-all-destinations" {{ 'selected="selected"' if request.query_dict.partner_type == 'show-all-types' }} &amp;gt;Show All&amp;lt;/option&amp;gt;
              {% set types = hubdb_table_column(hubdb_id, "partner_type").options %}
              {% for choice in types %}
                {% set type_list = type_list~choice.id|list %}
                {% if choice.id == request.query_dict.partner_type %}
                  &amp;lt;option selected="selected" value="{{ choice.id }}"&amp;gt;{{ choice.name }}&amp;lt;/option&amp;gt;
                {% else %}
                  &amp;lt;option value="{{ choice.id }}"&amp;gt;{{ choice.name }}&amp;lt;/option&amp;gt;
                {% endif %}
              {% endfor %}
            &amp;lt;/select&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;h4&amp;gt;Partner Tier&amp;lt;/h4&amp;gt;
            &amp;lt;select name="partner_tier" form="form_id" onChange="this.form.submit()" &amp;gt;
              &amp;lt;option value="" disabled&amp;gt;- Partner Tier -&amp;lt;/option&amp;gt;
              &amp;lt;option value="show-all-destinations" {{ 'selected="selected"' if request.query_dict.partner_tier == 'show-all-tiers' }} &amp;gt;Show All&amp;lt;/option&amp;gt;
              {% set tiers = hubdb_table_column(hubdb_id, "partner_tier").options %}
              {% for choice in tiers %}
                {% set tier_list = tier_list~choice.id|list %}
                {% if choice.id == request.query_dict.partner_tier %}
                  &amp;lt;option selected="selected" value="{{ choice.id }}"&amp;gt;{{ choice.name }}&amp;lt;/option&amp;gt;
                {% else %}
                  &amp;lt;option value="{{ choice.id }}"&amp;gt;{{ choice.name }}&amp;lt;/option&amp;gt;
                {% endif %}
              {% endfor %}
            &amp;lt;/select&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;div style="margin-top: 20px"&amp;gt;
            &amp;lt;input id="submit-button" type="submit" value="Enter"&amp;gt;
            &amp;lt;div style="margin-top: 20px"&amp;gt;
              &amp;lt;a href="/test-partner-locator-page"&amp;gt;Reset Filters&amp;lt;/a&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;
      &amp;lt;/div&amp;gt;

      
     
       
      {% set queryparam = "" %}
      
      {% if request.query_dict.partner_country in selected_countries %}
        {% set queryparam = queryparam ~ "&amp;amp;partner_country__in="~selected_countries|join(',')|urlencode %}
      {% endif %}

      {% if request.query_dict.partner_type in types|map('id','') %}
        {% set queryparam = queryparam ~ "&amp;amp;partner_type="~request.query_dict.partner_type|urlencode %}
      {% endif %}

      {% if request.query_dict.partner_tier in tiers|map('id','') %}
        {% set queryparam = queryparam ~ "&amp;amp;partner_tier="~request.query_dict.partner_tier|urlencode %}
      {% endif %}

      {% if request.query_dict.partner_region in regions|map('id','') %}
        {% set queryparam = queryparam ~ "&amp;amp;partner_region="~request.query_dict.partner_region|urlencode %}
      {% endif %}

      {# Listing #}

      {# Use this if you don't want automatic search before selecting fields #}
      {#
      {% if request.query_dict.warehouse_location &amp;amp;&amp;amp; request.query_dict.destination_country %}
      #}
        {% set table = hubdb_table_rows(hubdb_id, queryparam) %}
        {% if table == [] %}
          &amp;lt;p class=‘align-center’&amp;gt;Sorry, no listings found for that Search. Try changing your filter and search again.&amp;lt;/p&amp;gt;
        {% else %}
          {% for row in table %}
          &amp;lt;div&amp;gt;
          &amp;lt;div class="item"&amp;gt;
            &amp;lt;h4&amp;gt;Partner:&amp;lt;/h4&amp;gt;
            &amp;lt;p&amp;gt;{{ row.partner_name }}&amp;lt;/p&amp;gt;
          &amp;lt;/div&amp;gt;
    
          &amp;lt;div class="item"&amp;gt;
            &amp;lt;h4&amp;gt;Partner Type:&amp;lt;/h4&amp;gt;
            &amp;lt;p&amp;gt;{{ row.partner_type.name }}&amp;lt;/p&amp;gt;
          &amp;lt;/div&amp;gt;
    
          &amp;lt;div class="item"&amp;gt;
            &amp;lt;h4&amp;gt;Partner region:&amp;lt;/h4&amp;gt;
            &amp;lt;p&amp;gt;{{ row.partner_region.name}}&amp;lt;/p&amp;gt;
          &amp;lt;/div&amp;gt;
    
          &amp;lt;div class="item"&amp;gt;
            &amp;lt;h4&amp;gt;Partner tier:&amp;lt;/h4&amp;gt;
            &amp;lt;p&amp;gt;{{ row.partner_tier.name}}&amp;lt;/p&amp;gt;
          &amp;lt;/div&amp;gt;
    
          &amp;lt;div class="item"&amp;gt;
            &amp;lt;h4&amp;gt;Partner Country:&amp;lt;/h4&amp;gt;
            {% for product in row.partner_country %}
            {{ product.name }}{% if !loop.last %}, {% endif %}
            {% endfor %}
          &amp;lt;/div&amp;gt;
    
          &amp;lt;hr&amp;gt;
        &amp;lt;/div&amp;gt;
          {% endfor %}
        {% endif %}

&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Apr 2021 18:48:12 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Managing-Multiple-Filters-in-HubDB/m-p/427505#M22439</guid>
      <dc:creator>ckingg</dc:creator>
      <dc:date>2021-04-13T18:48:12Z</dc:date>
    </item>
  </channel>
</rss>

