使用Datatables v1.10
我想导出我的表,包括表外的HTML元素,其中包括薪金列的总和-这可能吗?该总和是动态变化的,单击按钮时应导出实时结果。
我创建了一个表,该表可以成功过滤,显示总数并导出带有自定义消息的PDF,但是我不确定如何将total
元素添加到PDF。
我希望PDF布局如下:
PDF标题
工资总额
表内容
我在这里创建了一个小提琴,下面是代码。
window.onload = function() {
$(document).ready(function() {
$('#example').DataTable({
dom: 'Bfrtip',
buttons: [{
extend: 'pdfHtml5',
messageTop: 'PDF created by PDFMake with Buttons for DataTables.'
}],
"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(4)
.data()
.reduce(function(a, b) {
return intVal(a) + intVal(b);
}, 0);
// Total over this page
pageTotal = api
.column(4, {
page: 'current'
})
.data()
.reduce(function(a, b) {
return intVal(a) + intVal(b);
}, 0);
// Update footer
$(api.column(4).footer()).html(
'$' + pageTotal + ' ( $' + total + ' total)'
);
$('#total').text('£' + Number(pageTotal).toFixed(2));
}
});
});
}
相关分类