0

Apologies if this has been asked before, but I can't seem to find a concise answer and I'm a rather light developer in jQuery.

I have a stack of objects which contain a variety of tags as class, including color and date as long-form number:

    <div class="red sysdate20110712"></div>
    <div class="blue sysdate20110712"></div>
    <div class="blue sysdate20120314"></div>
    <div class="red sysdate20110712"></div>
    <div class="yellow sysdate20100813"></div>
    <div class="red sysdate20100813"></div>
    <div class="yellow sysdate20121001"></div>
    <div class="blue sysdate20121001"></div>

What I would like to do is build functionality for users to filter first by color, then by date range, for example:

Date Start: 10.3.2010, Date End: 8.23.2013, color = blue and red.

After a bit of research, I have a date range working as a modification from this post. I eventually hope to link the min and max dates to a slider.

var minDate = 20120101;
var maxDate = 20130813;

var dateValue = [];
dateValue = $('.color-shape').filter(function(index){
var $this = $(this);
var matcharr = $this.attr('class').match(/sysdate([0-9]*)/);
if (matcharr) {
    var date = parseInt(matcharr[1]);
    return ((date >= minDate) && (date <= maxDate));
} else {
    return false;
}
});

Additionally, I have the color property filtered via combination filter method using checkboxes:

$checkboxes.change(function(){
var filters = [];
// get checked checkboxes values
$checkboxes.filter(':checked').each(function(){
  filters.push( this.value );
});

filters = filters.join(', ');

$container.isotope({ filter: filters });
});

My question is, how (if at all) can I combine these two elements? Since an object needs to be passed to filter, is there any way to combine the objects, or perhaps run a two-part filter?

Apologies if the answer is right in front of me as I'm a bit new to jQuery this deep.

UPDATE: With the help of a friend I got through some of this! Basically it involves creating a third var and pushing the arrays together in to a new object.

Community
  • 1
  • 1

1 Answers1

0

Why don't you use combination filter provided by the owner? It also has a version with hash history too

http://isotope.metafizzy.co/tests/combo-sort-history.html

rob.m
  • 9,843
  • 19
  • 73
  • 162
  • So I plan on incorporating the hash history too, but what I'm trying to do here is combine two types of filter objects in to one (date range and event type), not necessarily sort. – josh_e_washie Aug 14 '13 at 16:47
  • that doens't just sort but combines different filters too – rob.m Aug 15 '13 at 11:13