使用Datatables v1.10我想導出我的表,包括表外的HTML元素,其中包括薪金列的總和-這可能嗎?該總和是動態(tài)變化的,單擊按鈕時應導出實時結(jié)果。我創(chuàng)建了一個表,該表可以成功過濾,顯示總數(shù)并導出帶有自定義消息的PDF,但是我不確定如何將total元素添加到PDF。我希望PDF布局如下:PDF標題工資總額表內(nèi)容我在這里創(chuàng)建了一個小提琴,下面是代碼。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)); } }); });}
數(shù)據(jù)表PDF導出自定義總和元素
ibeautiful
2021-04-01 13:14:50