标签:contex foo 举例 filter 关闭 als search class 关于
var table;
table = $(‘#example‘).DataTable({
dom: ‘Bfrtip‘,
scrollY: true,
scrollX: true,
scrollCollapse: true,
colReorder: true,
select: true,
stateSave: true,
//info: false,//关闭左下角关于行数和选中的提示
//filter: false,//关闭搜索
//paging: false,//关闭分页
pagingType: "full_numbers",
columns: [
{ title: "Name", data: "Name", className: "center" },
{ title: "Position", data: "Position" },
{ title: "Office", data: "Office" },
{ title: "Age", data: "Age" },
{ title: "Salary", data: "Salary", className: "canEditor" },
{ title: "操作", data: null, defaultContent: "<button type=‘button‘>编辑</button>" }
],
footerCallback: function (row, data, start, end, display) {
var api = this.api(), data;
var intVal = function (i) {
return typeof i === ‘string‘ ?
i.replace(/[\$,]/g, ‘‘) * 1 :
typeof i === ‘number‘ ? i : 0;
};
//当前页统计
total = api.column(4).data().reduce(function (a, b) { return intVal(a) + intVal(b); }, 0);
//全部统计
pageTotal = api.column(4, { page: ‘current‘ }).data().reduce(function (a, b) { return intVal(a) + intVal(b); }, 0);
$(api.column(4).footer()).html(
‘当前页:$‘ + pageTotal + ‘ ( 全部:$‘ + total + ‘)‘
);
},
language: {
url: dtsLanguage
}
});
<table id="example" class="table table-bordered table-condensed" style="white-space: nowrap;width:100%;cursor:pointer" cellspacing="0">
<tfoot>
<tr>
<th style="border-left:0;border-right:0"></th>
<th style="border-left:0;border-right:0"></th>
<th style="border-left:0;border-right:0"></th>
<th style="border-left:0;border-right:0"></th>
<th style="border-left:0;border-right:0">数据合计:</th>
<th style="border-left:0;border-right:0"></th>
</tr>
</tfoot>
</table>
var table;
table = $(‘#example‘).DataTable({
dom: ‘Bfrtip‘,
scrollY: true,
scrollX: true,
scrollCollapse: true,
colReorder: true,
select: true,
stateSave: true,
//info: false,//关闭左下角关于行数和选中的提示
//filter: false,//关闭搜索
//paging: false,//关闭分页
pagingType: "full_numbers",
columns: [
{ title: "Name", data: "Name", className: "center" },
{ title: "Position", data: "Position" },
{ title: "Office", data: "Office" },
{ title: "Age", data: "Age" },
{ title: "Salary", data: "Salary", className: "canEditor" },
{ title: "操作", data: null, defaultContent: "<button type=‘button‘>编辑</button>" }
],
footerCallback: function (row, data, start, end, display) {
var data = table.search();
var ds = table.search(data).context[0].aiDisplay;
var Sum = 0;
$.each(ds, function (i, e) {
var data = table.row(e).data();
Sum = Number(Sum) + Number(data.Salary);
});
$(".Sum").html(Sum);
}
language: {
url: dtsLanguage
}
});
<table id="example" class="display table table-striped table-over table-bordered" style="white-space: nowrap;width:100%;cursor:pointer" cellspacing="0">
<thead></thead>
<tbody></tbody>
<tfoot>
<tr bgcolor="#FFCC99">
<th style="border-left:0;border-right:0"></th>
<th style="border-left:0;border-right:0"></th>
<th style="border-left:0;border-right:0">合计:</th>
<th style="border-left:0;border-right:0" class="Sum"></th>
<th style="border-left:0;border-right:0"></th>
</tr>
</tfoot>
</table>
JQuery Datatables 实现对某一列的数据合计汇总
标签:contex foo 举例 filter 关闭 als search class 关于
原文地址:https://www.cnblogs.com/dennyw/p/14199952.html