0

Here Fiddle:http://jsfiddle.net/abhiklpm/ZEDR9/5/

Here I have Implemented Multiple checkbox with filter, But the filter is getting overriden on clicking the second checkbox

EX: If i click Shipping all the shipping will come in below table But at the same time if i click 1GB The intersection of shipping and 1GB should only come but shipping options getting overriden.

like If i click Shipping & 1GB Only (product) Memory1 only should come. Help me out in this

   **Script**

 $("input:checkbox").click(function () {
var showAll = true;
$('tr').not('.first').hide();
$('input[type=checkbox]').each(function () {
    if ($(this)[0].checked) {
        showAll = false;
        var status = $(this).attr('rel');
        var value = $(this).val();            
        $('td.' + status + '[rel="' + value + '"]').parent('tr').show();
    }
});
if(showAll){
    $('tr').show();
}
});
1

1 Answer 1

1

Try to create a filter set and loop through the filter and apply them like

var $checks = $("input:checkbox").click(function () {
    var $trs = $('tr').not('.first');

    var filters = {}, flag = false;
    $checks.filter(':checked').each(function () {
        var rel = $(this).attr('rel');
        filters[rel] = filters[rel] || [];
        filters[rel].push('.'+rel+'[rel="'+this.value+'"]');
        flag = true;
    })
    if (flag) {
        $trs.show();
        $.each(filters, function (rel, list) {
            $trs.not(':has('+list.join()+')').hide();
        });
    } else {
        $trs.show();
    }
});

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.