SharePoint JavaScript show the total items in a library or list   

Tags: SharePoint 2010, General
Technorati Tags: ,

Little script for getting the following result.

image

It will add the total list items of the current library or list in your paging element.

 

Script.

 

/// <reference name="MicrosoftAjax.js"/>
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.js"/>
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.Core.js"/>
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\core.js"/>
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.debug.js"/>
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.UI.debug.js"/>
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.UI.Core.debug.js"/>
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.UI.Dialog.debug.js"/>
/// <reference path="jquery-1.6.4.min.js" />
 
$(document).ready(function () {
 
    ExecuteOrDelayUntilScriptLoaded(ready, "sp.js");
 
    function ready() {
 
        var listID = SP.ListOperation.Selection.getSelectedList();
 
        if (listID != null) {
            var context = new SP.ClientContext.get_current();
 
            var web = context.get_site().get_rootWeb();
 
            var list = web.get_lists().getById(listID);
 
            context.load(list);
 
            context.executeQueryAsync(function (sender, args) {
 
                var count = list.get_itemCount();
 
                var totaaltext = $(".ms-paging").text() + " / ( " + count.toString() + " )";
 
                $(".ms-paging").text(totaaltext);
 
            }, function (sender, args) { });
        }
    }
});

 

For JavaScript  intellisense in visual studio => SharePoint intellisense for JavaScript in visual studio

 
Posted by  Gilissen Timmy  on  10/25/2011
0  Comments  |  Trackback Url  | 0  Links to this post | Bookmark this post with:        
 

Links to this post

Comments

Name *:
URL:
Email:
Comments:


CAPTCHA Image Validation