I just though I would share this small snippet I created which can be added to a Sharepoint page on a website, and then when called it will iterate through the leftmenu and for links to folders/list in the current site it will add a counter indicating the number of items in the given list.
It is very simple and naïve in its implementation, but I think the concept is pretty neat
function ShowFolderCount() {
var ctx = SP.ClientContext.get_current();
// point to get all the lists
var myLists = ctx.get_web().get_lists();
// Load all lists
var listinfoarray = ctx.loadQuery(myLists, "Include(Title, ItemCount, RootFolder)");
// async excute
ctx.executeQueryAsync(function () {
var listinfo = new Array();
// iterate to all items
for (var i = 0; i < listinfoarray.length; i++) {
var listdata = new Object();
var currentItem = listinfoarray[i];
listdata.title = currentItem.get_title();
listdata.count = currentItem.get_itemCount();
listdata.url = currentItem.get_rootFolder().get_serverRelativeUrl();
listinfo.push(listdata);
}
var submenus = jQuery(".ms-quickLaunch .menu .root ul.static");
submenus.each(function () {
var menu = jQuery(this);
var links = menu.find("a");
links.each(function () {
try{
var link = jQuery(this);
var url = unescape(link.attr("href"));
for (var t = 0; t < listinfo.length; t++) {
var c = listinfo[t];
if (url && url.startsWith(c.url)) {
link.find("span span").text(c.title + " (" + c.count + ")");
break;
}
}
}
catch(ex)
{}
}
);
}
);
}, function () { });
}