Skip to content
Nosce Te Ipsum
  • Home
  • About me
  • My COETAIL Blogs
    • Course 1
    • Course 2
    • Course 3
    • Course 4
  • Testimonials
    • Professional
    • Personal
Site Search

Total in calculated columns of Sharepoint lists

  • March 4, 2009March 4, 2009
  • by Muhammad
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Pin on Pinterest
Pinterest
Share on Reddit
Reddit
Email this to someone
email
Share on StumbleUpon
StumbleUpon
Digg this
Digg

now that’s a tough one. I had to do some research on this and finding many solutions varying from editing the list page in Sharepoint designer to editing the code of sharepoint list columns and the “Total” and one article explained to write a VB code for it. Well there’s a simple solution – although based on Java Script – but the script is available for free on Google Codes and I attach it here with this post – Download it here –

Now place this .js in a shared documents as you are going to link to it through your script and note the shortcut to this script.

For this to work:

  • you need to have totals working on one of the other columns.
  • After you have put totals (any kind) for another column in a view
  • edit the page and add a webpart on top
  • set the “chrome type” to none and in the source code editor type the code below
  • replacing http://my.sharepoint.com/doclib/ with the shortcut of your VLE + Doc. Lib where you uploaded the script
  • and change the column number (9 in this code) in var col (line 15) to the column number (in the list view) of the calculated column.
  • in line 16 you can change the format of prefix (currently $) to any other currency or leave it as “” for non-money format (instruction in code as well)
<script src=”http://my.sharepoint.com/doclib/jquery-126min.js” type=”text/javascript”></script>
<script type=“text/javascript”>
function addCommas(nStr) {//formats number
nStr += ”;
x = nStr.split(‘.’);
x1 = x[0];
x2 = x.length > 1 ? ‘.’ + x[1] : ”;
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, ‘$1’ + ‘,’ + ‘$2’);
}
return x1 + x2;
}
$(function() {//sums money in specific list column
var col = 4; //which column to sum
var m = “$”; //change to “” for non-money format
var arrayList = $(“table.ms-listviewtable:first> tbody:eq(2)> tr”).find(“>td:eq(“+col+“)”).get();
var x = 0;
var p1 = “”;
var p2 = “”;
$.each(arrayList, function(){
x += Number($(this).text().replace(/\$|,|\)/g, “”).replace(/\(/g,“-“));
});
if (x < 0) {//format for negative numbers
p1 = “(“;
p2 = “)”;
x = Math.abs(x);
}
$(“#aggr> tr:first> td:eq(“+col+“)”)
.css(“text-align”,“right”)
.html(“<b>Total = “+p1+m+addCommas(x.toFixed(2))+p2+“</b>”);
});
</script>

 

 

In case you want this to work with Group view, the code is below:

<script src=”http://my.sharepoint.com/doclib/jquery-126min.js” type=”text/javascript”>
<script type=“text/javascript”>
function addCommas(nStr) {//formats number
nStr += ”;
x = nStr.split(‘.’);
x1 = x[0];
x2 = x.length > 1 ? ‘.’ + x[1] : ”;
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, ‘$1’ + ‘,’ + ‘$2’);
}
return x1 + x2;
}
function CalcGroup(groupName) {//sums money in specific list column
var x = 0;
var m = “”;
var p1 = “”;
var p2 = “”;
if (groupName == ”) {
$(“table.ms-listviewtable:first> tbody:eq(2)”).attr(“id”,“tbod”);
}
var arrayList = $(“#tbod”+groupName+“> tr”)
.find(“>td:last”).get(); //array for groups
$.each(arrayList, function(i,e){
x += Number($(e).text().replace(/\$|,|\)/g, “”).replace(/\(/g,“-“));
if ($(e).text().indexOf(“$”) >= 0) { m = “$” };
});
if (x < 0) {//format for negative numbers
p1 = “(“;
p2 = “)”;
x = Math.abs(x);
}
if (arrayList.length > 0) {
$(“#aggr”+groupName+“> tr:first> td:last”)
.css(“text-align”,“right”)
.html(“<b>Total = “+p1+m+addCommas(x.toFixed(2))+p2+“</b>”);
}
}
//rewrite of WSS function
function ExpGroupRenderData(htmlToRender, groupName, isLoaded)
{
var tbody=document.getElementById(“tbod”+groupName+“_”);
var wrapDiv=document.createElement(“DIV”);
wrapDiv.innerHTML=“<TABLE><TBODY id=\”tbod”+groupName+“_\” isLoaded=\”“+isLoaded+“\”>”+htmlToRender+“</TBODY></TABLE>”;
tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody);
if (CalcGroup) {
CalcGroup(groupName+“_”);
}
}
$(function() {
CalcGroup(”);
});
</script>

Code courtesy of Paul Grenier – original post available here

Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Pin on Pinterest
Pinterest
Share on Reddit
Reddit
Email this to someone
email
Share on StumbleUpon
StumbleUpon
Digg this
Digg
Importing lists from Excel 2007
Spring returns to Beijing
Muhammad
column list Sharepoint total

Related articles

Searching a particular Document Library
Outlook, Vista and Sharepoint
Importing lists from Excel 2007
editing themes
CSS Definitions
Sharepoint Resources

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Me!

Follow Me On TwitterFollow Me On LinkedInFollow Me On PinterestFollow Me On About.meFollow Me On Wordpress
May 2025
M T W T F S S
« Oct    
 1234
567891011
12131415161718
19202122232425
262728293031  

2009 2010 2011 Amelie apache beijing birthday clearos crèpes debian december 2009 dubai email february firewall guide holidays ill install internet kuala lumpur linux list mac maheen mobile october 2009 outlook Pakistan raspberry raspberry pi router search Sharepoint smtp snow spring ubuntu unix VLAN VPN windows 7 winter xian Zimbra

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Categories

Licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Theme by Colorlib Powered by WordPress
  • Home
  • About me
  • My COETAIL Blogs
  • Testimonials