# HubDB filtering by custom module

**URL:** <https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908>\
**Category:** CMS Development\
**Created:** [August 21, 2018, 7:01am UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908 "2018-08-21T07:01:28Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 21, 2018, 7:01am UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/1 "2018-08-21T07:01:28Z")

</div>

Hi,

I’m currently building a custom module for a customer and got stuck on the “filter-feature”.

The customer wants to have the functionality that he inserts one module an then selects an option for “filter the rows by column option”.

I’ve got a HubDB Column with “industry” which is an option col.  
In the custom module I’ve insert an “selection” function and wanted to do something like

```auto
{% if widget.branche =='1'%}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Option1’) %}
{% elif widget.branche =='2'%}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Option2’) %}
{% endif %}

```

Option1 and Option2 are some placeholders for the options in the industry column.

What am I doing wrong and could someone provide me help, please?

Thanks in advance

regards

Anton

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 21, 2018, 11:51am UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/2 "2018-08-21T11:51:48Z")

</div>

@Anton - if this is a custom module in the design manager that you’re editing. I think you’re looking for “ **module.branche** ” not “ ~~widget.branche~~ ”. Test your output with

`{{module.branche|pprint}}`

this will help you debug in the future

* * *

If this answer helped, please, mark as solved 😄

* * *

[tim@belch.io](mailto:tim@belch.io) | [forms.belch.io](https://forms.belch.io) | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me [on slack](http://slack.belch.io/).

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 21, 2018, 1:22pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/3 "2018-08-21T13:22:40Z")

</div>

@tjoyce - thanks for the answer. I think my “problem” was a little bit misleading.  
I’m building a costume model for filtering and simultaneously displaying the HubDB content.

This is the whole moldule-code so far( without CSS)

```auto
{% if widget.job_anzahl =='5'%}
{% set table = hubdb_table_rows(XXXXXX, 'limit=5') %}
{% elif widget.job_anzahl =='10'%}
{% set table = hubdb_table_rows(XXXXXX, 'limit=10') %}
{% elif widget.job_anzahl =='15'%}
{% set table = hubdb_table_rows(XXXXXX, 'limit=15') %}
{% elif widget.job_anzahl =='20'%}
{% set table = hubdb_table_rows(XXXXXX, 'limit=20') %}
{% elif widget.job_anzahl =='25'%}
{% set table = hubdb_table_rows(XXXXXX, 'limit=25') %}
{% elif widget.job_anzahl =='30'%}
{% set table = hubdb_table_rows(XXXXXX, 'limit=30') %}
{% endif %}
{% if widget.branche =='1'%}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Anlagenbau’) %}
{% elif widget.branche =='2'%}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Automotive’) %}
{% endif %}

<div class="row">
 <div class="container">
 <div class="span12 job-rss-wrapper">
{% if widget.introtext_anzeigen %}
<div class="row">
 <div class="container">
 <div class="span12 intro-text-wrapper">
 {% if widget.introtext_headline %}
 <{{ widget.introtext_headline_size }}>{{ widget.introtext_headline_content }}</{{ widget.introtext_headline_size }}>
 {% endif %}
 <p class="intro-text">{{ widget.introtext }}</p>
 </div>
 </div>
</div>
{% endif %}
{% if table == []%}
<p class='align-center'>Sorry, no listings found for that Search. Try changing your fiter and search again.</p>
<div class="row rss-job-table-headline">
 <div class="container">
 <div class="span12 rss-job">
 <div class="span6 rss-job-name">Berufsbezeichnung</div>
 <div class="span6">
 <div class="span8 rss-job-location">Ort</div>
 <div class="span4 rss-job-more-details">Details</div>
 </div>
 </div>
 </div>
 </div>
 {% else %} 

 {% for row in table %}
<div class="row">
 <div class="container">
 <div class="span12 rss-job">
 <div class="span6 rss-job-name">{{ row["hs_name"] }}</div>
 <div class="span6">
 <div class="span8 rss-job-location">
 {% for location in row["location"] %}
 {{ location|attr('name') }}{% if !loop.last %}, {% endif %}
 {% endfor %}
 </div>
 <div class="span4 rss-job-button-wrapper"><div class="button"><a class="link" href="javascript&colon;;" data-href="{{ request.path }}">Details</a></div></div>
 </div>
 </div>
 </div>
 </div>
 {% endfor %}
 {% endif %}
 {% if widget.mehr_jobs_anzeigen %}
 <div class="row">
 <div class="container">
 <div class="rss-job-more-jobs-divider"></div>
 </div>
 </div>
 <div class="container">
 <div class="span12 rss-job-more-jobs">
 <div class="rss-job-more-job-inner-wrapper">
 <div class="rss-more-jobs-message"><p>{{ widget.mehr_jobs_text }}</p></div>
 <div class="rss-more-jobs-button"><div class="button"><a class="link" href="/jobs">{{ widget.mehr_jobs_button_text }}</a></div></div>
 </div>
 </div>
 </div>

 {% endif %}
</div>

</div>
 </div>

<script>
 $('.rss-job').last().addClass('last')
</script>

```

The

```auto
{% if widget.branche =='1'%}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Anlagenbau’) %}
{% elif widget.branche =='2'%}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Automotive’) %}
{% endif %}

```

part is, like the “widget.job\_anzahl”, an option(or widget) which is build into the module. Where the user/customer can customize the result that is shown by the module.

Hope this is more understandable.

Thanks

regards,

Anton

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 21, 2018, 2:44pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/4 "2018-08-21T14:44:36Z")

</div>

@Anton- “job\_anzahl” is a choice field you created within the module, correct?

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 21, 2018, 2:48pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/5 "2018-08-21T14:48:10Z")

</div>

@tjoyce - that’s correct, yes

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 21, 2018, 2:50pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/6 "2018-08-21T14:50:44Z")

</div>

@Anton - yea, I think the solution should still stand.

Use pprint filter to inspect your dictionary object

`{{widget.branche|pprint}} //probably results in null``{{module.branche|pprint}} //probably has the data you're looking for`

If you edit your choice field then choose “copy snippet”, does it say module or widget?

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 21, 2018, 3:19pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/7 "2018-08-21T15:19:46Z")

</div>

It says “module”.

So I’m inserted

`{{module.branche|pprint}}`

in a line, that is getting displayed and the page I’ve created for testing is showing me “(String: 1)”

edit: I’ve just tried to modify the code like this:

```auto
{% if module.branche == '1' %}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Anlagenbau’) %}
{% elif module.branche == '2' %}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Automotive’) %}
{% endif %}

```

but nothing changed. I’ve also tried to do

```auto
{% if module.branche == '1' %}
{% set table = hubdb_table_column(XXXXXX, ‘industry=Anlagenbau’) %}
{% elif module.branche == '2' %}
{% set table = hubdb_table_column(XXXXXX, ‘industry=Automotive’) %}
{% endif %}

```

But nothing changed either

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 21, 2018, 4:18pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/8 "2018-08-21T16:18:47Z")

</div>

@Anton - Let’s just make sure the “if” statements are the one’s causing you problems. Can you drop this code in your module and toggle between your choices to at least make sure the if statements aren’t evaluating properly?

```auto
{% if module.branche == '1' %}
branch = 1
{% elif module.branche == '2' %}
branch = 2
{% endif %}

```

be sure to save after each choice change and then hit preview.

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 22, 2018, 6:08am UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/9 "2018-08-22T06:08:36Z")

</div>

@tjoyce

when I’m dropping your “code” into the module and toggle between the the choises I can see "branch = 1 " or "branch = 2 ". So the if-statement is correct

edit:

Does it make any difference between a “select” and “multiselect”-column type for the “industry=XY”-part?

`{% set table = hubdb_table_rows(XXXXXX, ‘industry=Anlagenbau’) %}`

Just asking because the “industry” column is a multiselect-column

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 22, 2018, 11:31am UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/10 "2018-08-22T11:31:29Z")

</div>

@Anton - Make sure you aren’t querying the Hubdb by the label name, instead you should query it by the key value. Each dropdown option will have a value =\> label pair.

So, if your select looks like this for the industry in hubdb

`<option value="1">Anlagenbau</option>`

Your query should look like this:

```auto
{% set table = hubdb_table_rows(XXXXXX, ‘industry=1’) %}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Anlagenbau’) %}

```

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 22, 2018, 12:03pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/11 "2018-08-22T12:03:27Z")

</div>

@tjoyce - good idea.  
I’ve tried your suggestion, but it doesn’t work. 😕

Here are some screens, how it looks in HubDB

 ![180822-screen1.JPG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/4/e/4e5cd30c383c983427431356ae96a79cbf5c10a5.jpeg)  
how it looks in the HubDB table  
 ![180822-screen2.JPG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/b/fb5684eac6cb66d88686b126dca2fa8114871be2.jpeg)  
how it looks, when I want to edit the column

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 22, 2018, 12:38pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/12 "2018-08-22T12:38:55Z")

</div>

@Anton - If you do:

```auto
{% set table = hubdb_table_rows(XXXXXX, ‘industry=1’) %}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=2’) %}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=3’) %}

```

You don’t get different result sets? Do you know what the id of your choice options are, for sure?

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 22, 2018, 1:01pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/13 "2018-08-22T13:01:29Z")

</div>

@tjoyce - if I insert one after another without the if-statement, it works fine

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 22, 2018, 1:10pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/14 "2018-08-22T13:10:48Z")

</div>

@Anton - cool, let’s try 1 more thing, then I’m out of ideas 😄

```auto
{% set myFilter = '' %}
{% if module.branche == '1' %}
 {% set myFilter = "industry=1" %}
{% if module.branche == '2' %}
 {% set myFilter = "industry=2" %}
{% endif %}

{% set table = hubdb_table_rows(XXXXXX, myFilter) %}

```

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 22, 2018, 2:00pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/15 "2018-08-22T14:00:52Z")

</div>

@tjoyce - it works!!! You’ve made my day!

The only thing that left is to connect the other “if-statement” with this one.

I’ve tried

```auto
{% if module.job_anzahl =='5'%}
{% set table = hubdb_table_rows(XXXXXX, 'myFilter&limit=5') %}
{% elif module.job_anzahl =='10'%}
{% set table = hubdb_table_rows(XXXXXX, 'myFilter&limit=10') %}
...
{%endif%}

```

and

```auto
{% if module.job_anzahl =='5'%}
{% set table = hubdb_table_rows(XXXXXX, myFilter&'limit=5') %}
{% elif module.job_anzahl =='10'%}
{% set table = hubdb_table_rows(XXXXXX, myFilter&'limit=10') %}
...
{%endif%}

```

but non of those worked

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 22, 2018, 2:10pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/16 "2018-08-22T14:10:16Z")

</div>

@Anton - Nice!

Are you trying to concatenate the strings now?

```auto
{% set myLimit = '' %}
{% if module.job_anzahl =='5'%}
 {% set myLimit = "&limit=5" %}
{% elif module.job_anzahl =='10'%}
 {% set myLimit = "&limit=10" %}
{% endif %}

{% set table = hubdb_table_rows(XXXXXX, myFilter~myLimit) %}

```

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 22, 2018, 2:16pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/17 "2018-08-22T14:16:22Z")

</div>

@tjoyce - Yes!

Thanks a lot for the support!

It works awesome!

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 22, 2018, 2:17pm UTC](https://community.hubspot.com/t/hubdb-filtering-by-custom-module/9908/18 "2018-08-22T14:17:23Z")

</div>

@Anton - Woohoo! nice, glad it’s working.
