我的要求是,在数据表列中使用textbox
时,textbox
列的总和不在页脚总数中。
<thead>
<tr>
<th style="width: 30%">Salary Head</th>
<th style="width: 20%">Amount</th>
<th style="width: 20%">Type</th>
<th style="width: 30%">Actual Amount</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="3" style="text-align:right">Total:</th>
<th></th>
</tr>
</tfoot>
$('#list_table').DataTable( {
"searching": false,
"paging": false,
"ordering": false,
"autoWidth": false,
"bInfo": false,
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
total = api
.column( 3 )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
$( api.column( 3 ).footer() ).html(total.toFixed(3));
}
} );
} );
Datatable Normal列正在工作,但是当在Datatable中使用textbox列时,列的总和不起作用。
答案 0 :(得分:0)
尝试计算总和
var table = $('#example').DataTable();
table.column( 4 ).data().sum(); // as fees is your fourth column
更多信息:
http://www.datatables.net/plug-ins/api/sum()#
https://datatables.net/examples/plug-ins/api.html
否则请参考该链接:
https://codepedia.info/jquery-sum-of-textbox-values-in-table-column/