HubDB filtering by custom module

SOLVE
Advisor

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 

{% 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

 








check Did my post help answer your query? Help the Community by marking it as a solution
2 Accepted solutions

Accepted Solutions
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@Anton - cool, let's try 1 more thing, then I'm out of ideas Smiley Very Happy

{% 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) %}
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@Anton - Nice! 

Are you trying to concatenate the strings now?

{% 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) %}
17 Replies
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@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 Smiley Very Happy


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.

Reply
0 Upvotes
Advisor

@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)

 

{% 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 

 

{% 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








check Did my post help answer your query? Help the Community by marking it as a solution
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@Anton- "job_anzahl" is a choice field you created within the module, correct?

Reply
0 Upvotes
Advisor

@tjoyce - that's correct, yes








check Did my post help answer your query? Help the Community by marking it as a solution
Reply
0 Upvotes
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@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? 

 

Reply
0 Upvotes
Advisor

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:

{% 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 

{% 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








check Did my post help answer your query? Help the Community by marking it as a solution
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@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?

 

{% 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.

Reply
0 Upvotes
Advisor

@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








check Did my post help answer your query? Help the Community by marking it as a solution
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@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:

{% set table = hubdb_table_rows(XXXXXX, ‘industry=1’) %}
{% set table = hubdb_table_rows(XXXXXX, ‘industry=Anlagenbau’) %}
Reply
0 Upvotes
Advisor

@tjoyce - good idea. 
I've tried your suggestion, but it doesn't work. :/

Here are some screens, how it looks in HubDB

 

180822-screen1.JPGhow it looks in the HubDB table180822-screen2.JPGhow it looks, when I want to edit the column








check Did my post help answer your query? Help the Community by marking it as a solution
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@Anton - If you do:

{% 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?

Reply
0 Upvotes
Advisor

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








check Did my post help answer your query? Help the Community by marking it as a solution
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@Anton - cool, let's try 1 more thing, then I'm out of ideas Smiley Very Happy

{% 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) %}
Highlighted
Advisor

@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 

{% 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

{% 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








check Did my post help answer your query? Help the Community by marking it as a solution
Regular Advisor | Gold Partner | HubSpot Certified Trainer

@Anton - Nice! 

Are you trying to concatenate the strings now?

{% 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) %}
Advisor

@tjoyce - Yes! 

Thanks a lot for the support! 

It works awesome!








check Did my post help answer your query? Help the Community by marking it as a solution
Regular Advisor | Gold Partner | HubSpot Certified Trainer

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