2017-01-18 11 views
0

jqueryデータテーブルがあり、2つの列の合計を計算したい。テーブルの 初期jqueryデータテーブル内の2つの列の合計を計算する

$('#myTable').DataTable({ 
     autoWidth: false, 
     searching: false, 
    ... 
    initComplete: function (settings, json) { 
     // calculate sum and inject into second and third row in the footer 
    }); 
    }); 

<table id="myTable"> 
    <thead> 
     <tr> 
     <th>Id</th> 
     <th>Time one</th> 
     <th>Time two</th> 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
     <th></th> 
     <th></th> 
     <th></th> 
     </tr> 
    </thead> 
</table> 

アップデート:この列内の

バレスは似ています:

===================== 
| 1 | 01:15 | 10:00 | 
===================== 
| 9 | 11:44 | 0:120 

|

+2

正確にあなたの質問は何ですか?あなたはどんな問題に遭遇しましたか? –

+0

私は質問を言い換えることができます:私は、たとえば、3番目の列のフッターに合計します。 – user1765862

答えて

0

あなたは、DataTableのプラグインAPIを使用してそれを行うことができます。

// Simply get the sum of a column 
var table = $('#example').DataTable(); 
table.column(3).data().sum(); 

// Insert the sum of a column into the columns footer, for the visible 
    // data on each draw 
    $('#example').DataTable({ 
    drawCallback: function() { 
     var api = this.api(); 
     $(api.table().footer()).html(
     api.column(4, {page:'current'}).data().sum() 
    ); 
    } 
    }); 

もっと:https://datatables.net/plug-ins/api/sum()

+0

オペレータが行の合計行が –

+0

のフッターに含まれている列の合計か、むしろ新しい列を必要とするかどうかは不明です。 – user1765862

+0

このapiを使用することができます。 –

関連する問題