【发布时间】:2021-06-14 13:31:11
【问题描述】:
【问题讨论】:
标签: javascript html twitter-bootstrap html-table bootstrap-table
【问题讨论】:
标签: javascript html twitter-bootstrap html-table bootstrap-table
您可以使用 jQuery DataTable plugin 来实现这一点。它有类似的example here
【讨论】:
首先,将此添加到您的表格中,
<tfoot>
<tr>
<th colspan="6" class="text-right">Total: </th>
<th colspan="2"></th>
</tr>
</tfoot>
然后添加以下脚本:
$('.tableClassor#tableID').DataTable({
dom: '<"top">rt<"bottom"lfp><"clear">',
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( 6 )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0);
//Total over this page
pageTotal = api
.column( 6, {page: 'current'})
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
//Update footer
$(api.column( 6 ).footer() ).html(
'$ '+pageTotal +' ( $ '+ total +' total )'
);
}
})
调整colspan 值,使总数与您要统计的列对齐。
【讨论】: