locked
showing sums across all rows in sharepoint designer 2007 RRS feed

  • Question

  • i create custom dataview ,i want to display the sum of all rows,i use xslt value like this:

    select= "format-number(sum/dsqueryresponse/rows/row/@column"/>

    it work fine but it display only the count of the current page.  how to do to show sums across all rows and not just the current page

    Friday, February 10, 2012 11:03 PM

Answers

  • Hi,

    We can achieve this via JavaScript, by using GetListItems in SPServices to get all the list items, and count the sum of column, and then show the result in a text box control or other control in data view. Please follow the steps:

    1. Add a row in the data view where you want to show the sum in SharePoint Designer, and then add a textbox in the row to show the result.
    2. Add a Content Editor Web Part in this page, copy the code below into Source Editor.

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>

    <script type="text/javascript" src="http://come:100/sites/collection1/sub1/Shared Documents/jquery.SPServices-0.6.2.min.js"></script>

    <script type="text/javascript">

       $(document).ready(function(){

           var sum=0;

           $().SPServices({

             operation: "GetListItems",

             async: false,

             listName: "list2",

          completefunc: function(xData,Status){

            $(xData.responseXML).find("[nodeName='z:row']").each(function() {

             var num=$(this).attr('ows_number');

             if(num==null)

             {

                num=0;

             }

             sum=parseInt(sum)+parseInt(num);

            });

         }

      });

    $('#ctl00_m_g_840ca842_88af_4c06_8a26_1337336b97e3_TextBox1').val(sum);

    });

    </script>

    Note:
    1. you can download jquery.SPServices-0.6.2.min.js here: http://cdiscportal.digitalinfuzion.com/CT/Scripts/Forms/DispForm.aspx?ID=1, then upload it to your site and change the path above.
    2. Replace list name (list2) with your own list.
    3. Replace ‘ows_number’ with ‘ows_yourColumn’.
    4. Replace ctl00_m_g_840ca842_88af_4c06_8a26_1337336b97e3_TextBox1 with the id of the textbox you add.

    If anything unclear, please feel free to ask.

    Thanks.


    Emir Liu

    TechNet Community Support

    • Marked as answer by Mike Walsh FIN Wednesday, February 15, 2012 9:07 PM
    Tuesday, February 14, 2012 8:10 AM

All replies

  • Hi,

    We can achieve this via JavaScript, by using GetListItems in SPServices to get all the list items, and count the sum of column, and then show the result in a text box control or other control in data view. Please follow the steps:

    1. Add a row in the data view where you want to show the sum in SharePoint Designer, and then add a textbox in the row to show the result.
    2. Add a Content Editor Web Part in this page, copy the code below into Source Editor.

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>

    <script type="text/javascript" src="http://come:100/sites/collection1/sub1/Shared Documents/jquery.SPServices-0.6.2.min.js"></script>

    <script type="text/javascript">

       $(document).ready(function(){

           var sum=0;

           $().SPServices({

             operation: "GetListItems",

             async: false,

             listName: "list2",

          completefunc: function(xData,Status){

            $(xData.responseXML).find("[nodeName='z:row']").each(function() {

             var num=$(this).attr('ows_number');

             if(num==null)

             {

                num=0;

             }

             sum=parseInt(sum)+parseInt(num);

            });

         }

      });

    $('#ctl00_m_g_840ca842_88af_4c06_8a26_1337336b97e3_TextBox1').val(sum);

    });

    </script>

    Note:
    1. you can download jquery.SPServices-0.6.2.min.js here: http://cdiscportal.digitalinfuzion.com/CT/Scripts/Forms/DispForm.aspx?ID=1, then upload it to your site and change the path above.
    2. Replace list name (list2) with your own list.
    3. Replace ‘ows_number’ with ‘ows_yourColumn’.
    4. Replace ctl00_m_g_840ca842_88af_4c06_8a26_1337336b97e3_TextBox1 with the id of the textbox you add.

    If anything unclear, please feel free to ask.

    Thanks.


    Emir Liu

    TechNet Community Support

    • Marked as answer by Mike Walsh FIN Wednesday, February 15, 2012 9:07 PM
    Tuesday, February 14, 2012 8:10 AM
  • thank you,

    Wednesday, February 15, 2012 9:00 PM