Quantcast
Channel: NBStore Discussions Rss Feed
Viewing all articles
Browse latest Browse all 4081

New Post: Categorylist Questions - ItemCount and Childcategories

$
0
0
Hi again

If you still need a solution for counting up the items in the subcategories to the parent categories in the categorylist, here is how I solved this.

I am using the treeview category list and have set the itemtemplate to:
TreeNameTemplate:
<span class="CatMenuLeft">[TAG:CATEGORYNAME]</span>
TreeRightHTML:
(<span class="CatMenuRight">[TAG:PRODUCTCOUNT]</span>)
with this little jQuery script in document ready it works for me now:
$(document).ready(function() {  
        var $topCat = $($('#NBStoreTreeMenu')[0]);
        $.each($topCat.children('li'), function(index, val){
            $ulSub = $(val).children('ul');
            var sumLevel1 = 0;
            $.each($ulSub.children('li'), function(index, val){
                var sumLevel2 = 0;
                $.each($(val).find('ul span.CatMenuRight'), function(index2, val){
                    sumLevel2+=parseInt($(val).text());
                });
                var actVal = $(val).children('a').find('span.CatMenuRight');
                var newVal = parseInt(actVal.text()) + sumLevel2;
                actVal.text(newVal);
                sumLevel1+=sumLevel2;
            });
            var actTotal = $(val).children('a').find('span.CatMenuRight');
            var newTotal = parseInt(actTotal.text()) + sumLevel1;
            actTotal.text(newTotal);
        });
});
I hope this helps
regards
Gerald

Viewing all articles
Browse latest Browse all 4081

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>