Hi All
Currently someone can filter by topic and type but it just adds both filtered types to the results list. Channel Marketing Resources | 360insights For instance if someone selects Funds Management (topic) and Case Studies (type) it shows all items relating Funds Management and all the case studies. What I would like to show is just case studies about Funds Management.
HTML:
<div class="resource-grid">
{# Filters #}
<div class="resource-filters">
<form>
<div class="resource-filters__search">
<input type="text" placeholder="Search" onkeypress="return event.keyCode != 13;">
</div>
<div class="resource-filters__filter">
<fieldset>
<div class="resource-filters__filter-group mb-md">
<legend>Browse by Topic</legend>
<!--<h2 class="h4">Browse by Topic</h2>-->
{% set resources = hubdb_table_rows(module.hubdb_id) %}
{% set topics = hubdb_table_column(module.hubdb_id, "topic").options %}
{% for topic in topics %}
<label><input type="checkbox" value="topic-{{ topic.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") }}" {% if request.query_dict.topic == topic.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") %}checked{% endif %} />{{ topic.name }}</label>
{% endfor %}
</div>
</fieldset>
<fieldset>
<div class="resource-filters__filter-group mb-md">
<legend>Browse by Type</legend>
<!--<h2 class="h4">Browse by Type</h2>-->
{% set resources = hubdb_table_rows(module.hubdb_id) %}
{% set types = hubdb_table_column(module.hubdb_id, "type").options %}
{% for type in types %}
<label><input type="checkbox" value="type-{{ type.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") }}" {% if request.query_dict.type == type.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") %}checked{% endif %} />{{ type.name }}</label>
{% endfor %}
</div>
</fieldset>
<fieldset>
<div class="resource-filters__filter-group ">
<legend>Browse by Featured Topic </legend>
<!--<h2 class="h4">Browse by Featured Topic </h2>-->
{% set resources = hubdb_table_rows(module.hubdb_id) %}
{% set types = hubdb_table_column(module.hubdb_id, "featured_resource").options %}
{% for type in types %}
<label><input type="checkbox" value="featured-{{ type.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") }}" {% if request.query_dict.featured == type.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") %}checked{% endif %} />{{ type.name }}</label>
{% endfor %}
</div>
</fieldset>
</div>
</form>
</div>
{# Results #}
<div class="resource-items">
{% set queryparam = "orderBy=order&inactive=false" %}
{% set resources = hubdb_table_rows(module.hubdb_id, queryparam) %}
{% for resource in resources %}
<a href="{{ resource.link }}" {% if resource.open_link_in_new_tab %}target="_blank"{% endif %} class="resource-items__item {% for item in resource.featured_resource %}featured-{{ item.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") }} {% endfor %} {% for item in resource.topic %}topic-{{ item.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") }} {% endfor %} {% for item in resource.type %}type-{{ item.name|lower|replace(" ", "-")|replace("&-", "")|replace(",", "") }} {% endfor %}">
{% if resource.image %}
<img src="{{ resize_image_url(resource.image.url, 992, 620, 992) }}" loading="lazy" alt="{{ resource.name }}" class="resource-items__item-image">
{% endif %}
<div class="resource-items__item-details">
{% for item in resource.type %}
<p class="resource-items__type">{{ item.name }}</p>
{% endfor %}
<h3 class="resource-items__item-name">{{ resource.name }}</h3>
{% if resource.description %}
<p class="resource-items__item-description">{{ resource.description }}</p>
{% endif %}
<span class="button button--arrow button--notext">{{ resource.button_text if resource.button_text : 'Download' }}</span>
</div>
</a>
{% endfor %}
</div>
</div>
{{ require_js("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js", "head") }}
JS:
// quick search regex
var qsRegex;
var checkboxFilter;
// init Isotope
var $container = $('.resource-items');
// filter with checkboxes
var $checkboxes = $('.resource-filters__filter input');
var $quicksearch = $('.resource-filters__search input[type="text"]').keyup( function() {
qsRegex = new RegExp( $quicksearch.val(), 'gi' );
});
// debounce so filtering doesn't happen every millisecond
function debounce(fn, threshold) {
var timeout;
threshold = threshold || 100;
return function debounced() {
clearTimeout(timeout);
var args = arguments;
var _this = this;
function delayed() {
fn.apply(_this, args);
}
timeout = setTimeout(delayed, threshold);
};
}
// Match Height
function equalHeight() {
let counter = 0;
let tallestHeight = 0;
$('.resource-items__item').css('height', 'auto');
$('.resource-items__item:visible').each(function(i, el) {
counter++;
$(el).css('height', 'auto');
if($(el).height() > tallestHeight) {
tallestHeight = $(el).height();
}
if(counter % 3 == 0 && $(window).width() >= 992) {
for(; counter > 0; counter--) {
$('.resource-items__item:visible').eq(i-(counter-1)).css('height', tallestHeight);
}
tallestHeight = 0;
counter = 0;
} else if(counter % 2 == 0 && $(window).width() < 992 && $(window).width() >= 577) {
for(; counter > 0; counter--) {
$('.resource-items__item:visible').eq(i-(counter-1)).css('height', tallestHeight);
}
tallestHeight = 0;
counter = 0;
} else if($(window).width() < 577) {
$('.resource-items__item').css('height', 'auto');
} else if((i+1) == $('.resource-items__item:visible').length) {
for(; counter > 0; counter--) {
$('.resource-items__item:visible').eq(i-(counter-1)).css('height', tallestHeight);
}
}
});
$container.isotope('layout');
}
function Filter() {
// map input values to an array
var inclusives = [];
// inclusive filters from checkboxes
$checkboxes.each(function(i, elem) {
// if checkbox, use value if checked
if (elem.checked) {
inclusives.push(elem.value);
}
});
var text = $quicksearch.val()
$container.isotope({
itemSelector: '.resource-items__item',
percentPosition: true,
layoutMode: 'fitRows',
masonry: {
columnWidth: '.resource-items__sizer'
},
filter: function() {
var $this = $(this)
var searchResult = qsRegex ? $this.text().match( qsRegex ) : true;
var checkClass = inclusives.length == 0 ? true : false;
$.each(inclusives, function(index, c) {
var _class = $this.hasClass(c)
if (_class) {
checkClass = true;
return;
}
})
return searchResult && checkClass
}
});
setTimeout(function() {
equalHeight();
}, 500);
}
Filter();
$quicksearch.on('input', debounce(function() {
Filter();
}));
$checkboxes.change(function() {
Filter();
});
$(window).on('load', function(){
$(window).resize(function() {
equalHeight();
});
});
Thanks in advance for any help.




