Question

I have a Document Library list view web part (LVWP) on my SPO Page.

Because of the 5,000 item threshold, I had to disable any counts under the 'Totals' menu in the list view editor. However, I would like to know the total amount of documents/items displayed in the LVWP.

Is there some code or script that can be pasted into a script editor wp in order to achieve this?

Was it helpful?

Solution

I am not sure if you are referring to SP on-prem environment here or SPO, assuming we are using Classic SharePoint features here, the following concept is going to work for both the environment.

For classic page, place a script editor webpart on the page where you have List View WP added and paste the following code.

In SharePoint REST API we have the list/library end point to list total number of documents in it.
<path to site collection or web>/_api/web/lists/getbytitle('<List Title>')/ItemCount

Here is the complete code:

<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<div id="listItemCount"></div>
<script>
    $(document).ready(function(){
        var listTitle = "<Title of list goes here>";
        var siteURL = "https://<URL to Web where list is available>";

        var url = siteURL + "/_api/web/lists/getbytitle('" + listTitle + "')/ItemCount";
        $.getJSON(url, function(data){
            $("#listItemCount").text(data.value);
        }, function(error){
            // Code for error handling
        })
    });
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top