Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a SharePoint list that contains multiple columns of information.

There’s a Category column that’s a look up to another list called ‘Category’. This is to produce unique ID’s for each of those values.

Originally, I wrote some jQuery that would filter items in the list (using a selection of checkboxes, Category 1 / Category 2 etc) based on the individual category. However, now I wish to filter items in the list based on an item that has multiple categories. This is where I’m stuck. The code below currently works for filtering items with just one category.

Both the filter and content are in separate Content Query Web Parts.

XSLT

    <xsl:template name="list-items">
<div class="contact-container" SharePointID="{@ID}" Category="{@Category}" CategoryID="{@CategoryID}" Market="{@Market}" MarketID="{@MarketID}" href="#Popup-Container" >
    <a class="contact-items" href="#Popup-Container">
        <div class="title-container"><xsl:value-of select="@Title"/></div>
    </a>
</div>

jQuery

$('.checkbox[categoryid]').on("change",function(){

        if ( $('.checkbox:checked').size() == 0 ) {

            $('#item-container > .contact-container').show();

        } else {

            // We have just checked this checkbox 
            if ( $(this).is(":checked") ) {
                // This is the only checked checkbox (so hide everything)
                if ( $('.checkbox:checked').size() == 1 ) {
                    $('#item-container > .contact-container').hide();
                }
            } else {
                // Hide all matching this filter as we just unchecked it 
                $('#item-container > .contact-container[categoryid="' + $(this).attr('CategoryID') + '"]').hide();
            }

            // Only look at the items which have the matching category
            $('#item-container > .contact-container[categoryid="' + $(this).attr('CategoryID') + '"]').filter(function(index){
                if ( $('#category_' + $(this).attr('CategoryID') + ':checked').size() > 0 ||
                    $('#market_' + $(this).attr('MarketID') + ':checked').size() > 0) {
                    return true;
                }
                return false;
            }).show();              

        }

    });

Any help with this would be greatly appreciated.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.