tablesorter group subtotal based trigger col 0 add col 1

时间:2016-09-12 01:23:45

标签: jquery tablesorter

我正在尝试使用供应商列更改来累计AMOUNT列。换句话说,总计哈利金额和马克总金额。我还想将总数列在每个组下的金额列中。

编辑 - 我真的很喜欢这个"点击"在列上自动,换句话说,小计已经存在。按第一列排序,但在第二列排序。

我希望它看起来像这样:按第0列和第1列中的子总数排序

Mark    100.22
        232.12
 Total  342.34

Harry    23.21
         11.11
  Total  34.32

编辑 - 添加了此DEMO

enter image description here

$("#invoicesraw").tablesorter({
    theme : "blue",

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




        group_callback    : function($cell, $rows, column, table){
            if (column === 1) {
                var subtotal = 0;
                $rows.each(function(){
                    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
    }
});

这是使用总计时OUTPUT的示例,注意组名称行未格式化。

    Vendor,Amount
"<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
Total:,5710.21
"<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
Total:,3434.00

我将outputTable添加到了demo中,但它没有触发。不知道为什么我的测试网站上的代码相同。我不是很精通JSFiddle。

以下是最新的演示HERE

请注意为什么但是在JSFiddle上看起来很棒。在我的测试网站上,它将这些名称添加到CSV

    Vendor,Amount
harry smith (5),harry smith (5)
Harry Smith,3222.00
Harry Smith,2345.21
Harry Smith,121.00
Harry Smith,1.00
Harry Smith,21.00
Total:,5710.21
mark worsnop (1),mark worsnop (1)
Mark Worsnop,3434.00
Total:,3434.00

1 个答案:

答案 0 :(得分:1)

更改group_callback功能,如下所示(demo):

group_callback    : function($cell, $rows, column, table){
    if (column === 0) {
        var subtotal = 0;
        $rows.each(function(){
            subtotal += parseFloat( $(this).find("td").eq(1).text() );
        });
        $cell.find(".group-count").append("; total: " + subtotal.toFixed(2) );
    }
}
相关问题