Reply To: vLookup Group Item Count next to Group

Home Forums vLooup for SharePoint vLookup Group Item Count next to Group Reply To: vLookup Group Item Count next to Group

#31604

Hi Alexander,

Of course, I’ve combined it with a search field that hides the not matching items and also corrects the count to show the number of items found in the corresponding group.

The picture Brosch1 shows the form ready state where the items have been counted.
The picture Brosch2 shows the filled out search box and groups with 0 count are hidden as well.

The function for counting the items in the groups is shown below:


function countTotals()
{
    var groups = $('.vLookupGroup');
    $(groups).each(function(){
        var count = $(this).find('tr.vLookupTableRow:not(.hidden)').length;
        var curcount = $(this).siblings(".vLookupGroupHeader").find('.broschcount');
        if(curcount.length > 0) 
        {
            curcount.text(" ("+count+")");
        }
        else 
        {
            $(this).siblings(".vLookupGroupHeader").append("<span class='broschcount'> ("+count+")</span>");
        }
        
        if(count === 0) 
        {
            $(this).parent().addClass('hidden');
        } 
        else 
        {
            $(this).parent().removeClass("hidden");
        }
    });
}

When the vLookup is loaded, I’m counting the totals in the groups initially:


function vLookupIsLoadedCallback(fin){
    if(fin === "vLookup_Broschueren")
    {
        var groupsloaded = setInterval(function() {
            var groups = $('.vLookupGroup');
            if(groups.length > 0) 
            {
                clearInterval(groupsloaded);
                countTotals();
            }
        },1000);
    }
}

And when I’m searching for items I’m again refreshing the totals count:


function highlightMatches(elm, fin) {
    
     var sVal = jQuery(elm).val(),
        container = jQuery("#vLookup_" + fin + "_" + spjs.dffs.data.thisItemID).find(".vLookupTable");
    container.find("tr.vLookupTableRow").removeClass("hidden");
    if (sVal !== "") {
        container.find("tr.vLookupTableRow").each(function(i, tr) {
            if (jQuery(tr).text().toLowerCase().match(sVal.toLowerCase()) !== null) {
                //jQuery(tr).addClass("highlightSearchMatchInvLookup");
            }else{
                jQuery(tr).addClass("hidden");
            }
        });
    }
    countTotals();
}

Hope this will help someone else too 🙂

BR,
Chris