Widget:TableTotal: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
Recreated without the code which broke the server
 
No edit summary
Line 51: Line 51:
| 2014-07-15 || 10 RGB LEDs || £7.49 || Bob  
| 2014-07-15 || 10 RGB LEDs || £7.49 || Bob  
|}
|}


{{#widget:TableTotal|tableIndex=1}}
{{#widget:TableTotal|tableIndex=1}}
Line 62: Line 63:


   <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 99:
       });
       });
       $("<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>

Revision as of 13:22, 2 June 2016

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