| 1 | $(document).ready(function(){ |
|---|
| 2 | // Fields we will total |
|---|
| 3 | var columns = ['totalhours','estimatedhours']; |
|---|
| 4 | var tbodies = $('table.listing.tickets tbody'); |
|---|
| 5 | |
|---|
| 6 | tbodies.each(function(idx, tbody){ |
|---|
| 7 | tbody = $(tbody); |
|---|
| 8 | if(tbody.has('tr.even').length == 0) return true; |
|---|
| 9 | var tfoot = $('<tbody class="foot"></tbody>'); |
|---|
| 10 | var totalsRow = $('tr:first-child',tbody).clone(); |
|---|
| 11 | tfoot.append(totalsRow); |
|---|
| 12 | |
|---|
| 13 | // Build footer row |
|---|
| 14 | $('td',totalsRow).empty() |
|---|
| 15 | .css('background-color','#EEF') |
|---|
| 16 | .css('text-align','right') |
|---|
| 17 | .css('padding','0.1em 0.5em') |
|---|
| 18 | .css('border','1px solid #DDD'); |
|---|
| 19 | |
|---|
| 20 | $.each(columns,function(idx, field){ |
|---|
| 21 | // count totals |
|---|
| 22 | var total = 0; |
|---|
| 23 | $('td.'+field,tbody).each(function(cidx, cell){ |
|---|
| 24 | $(cell).css('text-align','right'); |
|---|
| 25 | var val = Number($(cell).text()); |
|---|
| 26 | if(!isNaN(val))total+=val; |
|---|
| 27 | }); |
|---|
| 28 | |
|---|
| 29 | //set total text in each footer row |
|---|
| 30 | $('td.'+field,totalsRow).text(total.toString()); |
|---|
| 31 | }); |
|---|
| 32 | |
|---|
| 33 | // attach footer row |
|---|
| 34 | tbody.after(tfoot); |
|---|
| 35 | }); |
|---|
| 36 | }); |
|---|