Widget:TableTotal: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
Recreated without the code which broke the server
 
 
(4 intermediate revisions by one other user not shown)
Line 53: Line 53:


{{#widget:TableTotal|tableIndex=1}}
{{#widget:TableTotal|tableIndex=1}}
 
[[Category:Widget]]


</noinclude>
</noinclude>
Line 62: Line 62:


   <script type="text/javascript">
   <script type="text/javascript">
     $(document).ready(function () {
 
     function defer(method) {
        if (window.jQuery)
            method();
        else
            setTimeout(function() { defer(method) }, 50);
    }   
 
 
    defer(function() {
    //$(document).ready(function () {
       var total = 0;
       var total = 0;
       var groups = {};
       var groups = {};
Line 88: Line 98:
       });
       });
       $("<p><b>Total:</b> £" + total.toFixed(2) + "</p>").appendTo('#tableTotal<!--{$tableTotalDivId|escape:'html'}-->');
       $("<p><b>Total:</b> £" + total.toFixed(2) + "</p>").appendTo('#tableTotal<!--{$tableTotalDivId|escape:'html'}-->');
     });
     //});
});
   </script>
   </script>
   <!-- TableTotal code ends here -->
   <!-- TableTotal code ends here -->
</includeonly>
</includeonly>

Latest revision as of 23:59, 5 April 2019

This widget can be used to calculate the total of values in a table column and aditionally provide grouped totals based on values in another column.

Using this widget

You can insert a table total with the following wiki code:

{{#widget:TableTotal|tableIndex=0|totalColumn=2|groupColumn=3}}

Parameters

tableIndex
The index of the table on the page containing the values (0 = the first table). Default: 0
totalColumn
The index of the column within the table which contains the values (0 = the first column). Default: 2
groupColumn
The index of the column within the table which contains the group information (0 = the first column). Optional.

Examples

{{#widget:TableTotal|tableIndex=0|totalColumn=2|groupColumn=3}}
Date Item Price Buyer
2014-07-10 Plywoood £22.99 Alice
2014-07-15 M3 Bolts £3.50 Alice
2014-07-15 10 RGB LEDs £7.49 Bob

{{#widget:TableTotal|tableIndex=1}}
Date Item Price Buyer
2014-07-10 Plywoood £22.99 Alice
2014-07-15 M3 Bolts £3.50 Alice
2014-07-15 10 RGB LEDs £7.49 Bob