[英]calculate sum of two columns inside jquery datatables
我有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
|
您可以使用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()
);
}
} );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.