mixitup
mixitup copied to clipboard
multiple filter need help
I am trying to use two filter group, with 'and' logic between them, and 'or' logic inside each group. I will be like Parks demo.
I get the code of the demo and i have try to implement in my web but i can. This is the code:
jQuery(document).ready(function(){
jQuery('#portfolio-list').mixitup({
effects: ['fade'],
easing: 'smooth',
transitionSpeed: 1000,
multiFilter: true,
resizeContainer: false,
});
});
// HANDLE MULTI-DIMENSIONAL CHECKBOX FILTERING
/*
* The desired behaviour of multi-dimensional filtering can differ greatly
* from project to project. MixItUp's built in filter button handlers are best
* suited to simple filter operations, so we will need to build our own handlers
* for this demo to achieve the precise behaviour we need.
*/
var $filters = $('#filters').find('li'),
dimensions = {
asignatura: 'all', // Create string for first dimension
format: 'all' // Create string for second dimension
};
// Bind checkbox click handlers:
$filters.on('click',function(){
var $t = $(this),
dimension = $t.attr('data-dimension'),
filter = $t.attr('data-filter'),
filterString = dimensions[dimension];
if(filter == 'all'){
// If "all"
if(!$t.hasClass('active')){
// if unchecked, check "all" and uncheck all other active filters
$t.addClass('active').siblings().removeClass('active');
// Replace entire string with "all"
filterString = 'all';
} else {
// Uncheck
$t.removeClass('active');
// Emtpy string
filterString = '';
}
} else {
// Else, uncheck "all"
$t.siblings('[data-filter="all"]').removeClass('active');
// Remove "all" from string
filterString = filterString.replace('all','');
if(!$t.hasClass('active')){
// Check checkbox
$t.addClass('active');
// Append filter to string
filterString = filterString == '' ? filter : filterString+' '+filter;
} else {
// Uncheck
$t.removeClass('active');
// Remove filter and preceeding space from string with RegEx
var re = new RegExp('(\\s|^)'+filter);
filterString = filterString.replace(re,'');
};
};
// Set demension with filterString
dimensions[dimension] = filterString;
// We now have two strings containing the filter arguments for each dimension:
console.info('dimension 1: '+dimensions.asignatura);
console.info('dimension 2: '+dimensions.format);
/*
* We then send these strings to MixItUp using the filter method. We can send as
* many dimensions to MixitUp as we need using an array as the second argument
* of the "filter" method. Each dimension must be a space seperated string.
*
* In this case, MixItUp will show elements using OR logic within each dimension and
* AND logic between dimensions. At least one dimension must pass for the element to show.
*/
$('#portfolio-list').mixitup('filter',[dimensions.asignatura, dimensions.format])
});
Width this code it doesnt work. Filter are selected but items dont changes. I f only use the part of the code to initialice mixitup, Then, it work but only with 'and' logic.:
jQuery(document).ready(function(){
jQuery('#portfolio-list').mixitup({
effects: ['fade'],
easing: 'smooth',
transitionSpeed: 1000,
multiFilter: true,
resizeContainer: false,
});
});
How can i achieve something like Parks demo?