[英]calculate sum of two columns inside jquery datatables
I have jquery datatable and I want to calculate sum of two columns. 我有jQuery数据表,我想计算两列的总和。 initialization of the table
表的初始化
$('#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>
Update: 更新:
vales inside this columns are like: 此列中的值类似于:
=====================
| 1 | 01:15 | 10:00 |
=====================
| 9 | 11:44 | 0:120
| |
You can do it using DataTable Plugin API: 您可以使用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()
);
}
} );
More: https://datatables.net/plug-ins/api/sum() 更多: https : //datatables.net/plug-ins/api/sum()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.