0

Good Morning;

I have a Custom List with a single column recording costs. I want to add the entire column (vertically) to give me a total. So far I have only been able to find advice on adding across columns. Any help?

I am running Sharepoint 2013 OP with SPD2013.

1

2 Answers 2

0

You can run a function that will do that, and place an HTML textbox on the page to show the results. Try doing this:

<script scr="https://youSPSite/SiteAssets/jquery-2.x.x.js"></script>
<script type="text/javascript>

$(document).ready(function() {
    getTotal();
});
function getTotal(){
    var total = 0;
    var call = jQuery.ajax({

        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Your List Name')/items",
        type: "GET",
        datatype: "json",
        headers: { Accept: "application/json;odata=verbose" }
    });

    call.done(function (data){
        //console.dir(data) uncomment this to view your data and make sure your function is working in the DEV tool bar on the console
        var results = data.d.results;
        for (i = 0; i < results.length; i++) {
            total += results[i].YourColumnToAdd;
        }
        var html = "<input type='text' value='" + total + "' id='txtBox' />";
        $(".myTotal").append(html);
    });
}
</script>

<div class="myTotal"></div>

This is a simple solution that should work to get the results you are looking for. You can play with styling and where to put it on the page. Hope this helps!

EDIT: I have adjusted the code to work in a Text file you can then use to run the code in a ContentEditorWebPart. It is best practices to use a txt file and reference it instead of putting code directly into the CEWP. CEWP will render HTML, CSS, JavaScript, C# (if security permits), and anything you can reference really. You will have to get the jQuery library and store it in your Site Assets Library and then reference it in you code (look above).

To add your web part, edit the page, and click the Add Web Part link on the page. The ContentEditor is under Content and Structure. Select the CEWP and put it on the page. Edit the CEWP and place a link to your txt file you used for code in the URL block of the CEWP properties. test the link to make sure it is correct then hit OK. Use your DEV toolbar to troubleshoot anything that might not be working just right. The txt file should be stored in your Site Assets Library.

3
  • How would I go about using this via a WebPart?
    – Daryl
    Commented Jan 15, 2019 at 15:28
  • You can use a ContentEditorWebPart on your custom list page and use this code. I will update my answer to explain...
    – lazoDev
    Commented Jan 15, 2019 at 15:48
  • Check it now :)
    – lazoDev
    Commented Jan 15, 2019 at 16:04
0

You can add Total Rows in each View by editing it.

Open view which you want to edit > Section Totals > Select Column.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.