2

I am working on a list and I want to show the Sum of items inside my list view. so as mentioned in this Technet article, I wrote the following JSLINK:

https://social.technet.microsoft.com/wiki/contents/articles/30317.sharepoint-2013-displaying-sum-for-calculated-column-in-a-list-view-using-jslink.aspx

but the problem I am facing is that the JSLINK will show the SUM per page and not per list. so if I have a list of 200 items and I am showing 10 items per page.. then the SUM will be the sum for each 10 items separately.

5

1 Answer 1

3

Before we get into how you can do the sum for all items in the list, whether or not they are shown, let's briefly talk about why you actually might not want to do that.

If you do not sum all the items in the list, but only sum the items shown, you preserve the ability to show different sums depending on how the view has been filtered. This may be valuable information for your users. In the example you linked to, it showed 4 projects, the calculated column "Total Billing" for each project, and then the sum of the "Total Billing" for all 4 projects. What if there was another column we are not seeing called "Region", and those 4 projects were visible because the user had filtered by one region. It's perfectly plausible that a user might say "I want to see the total billing for Region X," come to the list, filter by Region to see the projects for that region, and then want to see the sum total of all the Total Billing values for all those projects.

If you always show the sum for all items in the list, you lose that ability.

That being said, if you did want to always show the sum for all items in the list (visible or not), I would just set up an async call in OnPostRender (either using JSOM or REST, personally I am preferring REST these days) to get the Total Billing values for all list items, and then when you get that response, add them together and display the resulting sum.

You almost don't even need to hook into the CSR system to do that, you could just set up your JSLink to pull in jQuery and another file where you do everything in $(document).ready().

(And of course you don't even really need to use jQuery, but like I said, I have been preferring REST these days and jQuery's $.ajax() makes those calls pretty easy to do.)

3
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Benny Skogberg
    May 17, 2017 at 9:55
  • @Dylan now is there a way to achieve something as follow... to create new site columns same as the one i am using for the calculated columns.. then i will create these columns using power-shell and i will set them to be hidden on the create and edit form.. also will disable them inside the quick grid using JSLINK.. now the only issue will be is how i need to populate their values... now instead of using workflow.. can i define that the defualt value for these columns to b equal to the related calculated column???
    – John John
    May 17, 2017 at 14:59
  • @Dylan if this is not possible ... then can i force my workflow 2013 to update the list fields,, without creating a new version for the items ??
    – John John
    May 17, 2017 at 14:59

Your Answer

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

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