Mark Worsnop Mark Worsnop - 1 year ago 135
jQuery Question

tablesorter group subtotal based trigger col 0 add col 1

I am trying to total the AMOUNT column with the vendor column changes. In other words the total of Harry Amount and the total of Mark amount. I would also like to put the total in the amount column under each group.

EDIT - I would really like this to "click" on the column automatically, in other words the subtotal will already be there. sorted by the 1st column but totals in the 2nd column.

What I would like it to look like is this: Sort by column 0 and sub total in column 1

Mark 100.22
Total 342.34

Harry 23.21
Total 34.32

EDIT - Added this DEMO

enter image description here

theme : "blue",

widgets: [ "group", "columns", "columnSelector", "zebra" ],
widgetOptions: {

group_callback : function($cell, $rows, column, table){
if (column === 1) {
var subtotal = 0;
subtotal += parseFloat( $(this).find("td").eq(column).text() );
$cell.find(".group-count").append("; subtotal: " + subtotal );
// event triggered on the table when the grouping widget has finished work
group_complete : "groupingComplete",

columnSelector_container : $('#selector'),
columnSelector_columns : {
0: 'disable',
1: 'disable',
2: 'disable'
columnSelector_mediaquery: false

This is a sample of the OUTPUT when using the totals, NOTE the group name line is not formatted.

"<i></i><span class=“;group-name“;>harry smith</span><span class=“;group-count“;> (5)</span>","<i></i><span class=“;group-name“;>harry smith</span><span class=“;group-count“;> (5)</span>"
Harry Smith,3222.00
Harry Smith,2345.21
Harry Smith,121.00
Harry Smith,1.00
Harry Smith,21.00
"<i></i><span class=“;group-name“;>mark worsnop</span><span class=“;group-count“;> (1)</span>","<i></i><span class=“;group-name“;>mark worsnop</span><span class=“;group-count“;> (1)</span>"
Mark Worsnop,3434.00

Answer Source

Change the group_callback function as follows (demo):

group_callback    : function($cell, $rows, column, table){
    if (column === 0) {
        var subtotal = 0;
            subtotal += parseFloat( $(this).find("td").eq(1).text() );
        $cell.find(".group-count").append("; total: " + subtotal.toFixed(2) );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download