我有jquery数据表,我想计算两列的总和。 表的初始化
$('#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
|
答案 0 :(得分:0)
您可以使用DataTable Plugin 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()
);
}
} );