我有一个现有的模块,它(使用DataTables (jQuery))显示表中的数据,最终用户要求它们能够打印数据。
$('.js-dataTable-full-agedDebt').DataTable({
ajax: {
url: 'inc/ajax/tables/payable/aged-debt.php',
type: "post",
data: function(d){
d.depot = Depot;
d.group = Group;
}
},
dom: 'Bfrtip',
pagingType: "full_numbers",
buttons: [
'print'
],
order: [1., 'asc'],
"deferRender": true,
scrollY: "500px",
paging: false,
columns: [
{"data": "Account"},
{"data": "Term"},
{"data": "Credit"},
{"data": "Total"},
{"data": "Amount"},
{"data": "Month1"},
{"data": "Month2"},
{"data": "Month3"},
{"data": "Month4"},
{"data": "Month5"},
{"data": "Action"},
{"data": "balanceMonthRemit"},
{"data": "balanceMonth"},
{"data": "balanceMonthMinusOne"},
{"data": "balanceMonthMinusTwo"},
{"data": "balanceMonthMinusThree"},
{"data": "balanceOlder"},
],
"columnDefs": [
{"visible": false, "targets": [11, 12, 13, 14, 15, 16]},
{"orderData": [ 11 ], "targets": 4 },
{"orderData": [ 12 ], "targets": 5 },
{"orderData": [ 13 ], "targets": 6 },
{"orderData": [ 14 ], "targets": 7 },
{"orderData": [ 15 ], "targets": 8 },
{"orderData": [ 16 ], "targets": 9 },
]
}这在正常情况下是可以的,但是,这个表没有默认值。90%的单元格中的值是带有popOver的锚定标记(它显示了一个较小的数据表,其中显示了计算)。
<a onmouseover="popupDataActivityTotal("CN000141-N")" onmouseout="popupDataActivityTotalClose("CN000141-N")" class="popOver" id="activityTotalCN000141-N" style="color:#3f9ce8;" data-toggle="popover" data-html="true" title="" data-placement="bottom" data-content="
<table class="table table-bordered table-striped">
<thead>
<th class="pl-15 pr-15">Doc Type</th>
<th class="pl-15 pr-15">Doc Num</th>
<th class="pl-15 pr-15">Doc Date</th>
<th class="pl-15 pr-15">Due Date</th>
<th class="pl-15 pr-15">Open Amount</th>
</thead>
<tbody>
<tr>
<td class="pl-15 pr-15">Invoice</td>
<td class="pl-15 pr-15">600054871</td>
<td class="pl-15 pr-15">18th June 2021</td>
<td class="pl-15 pr-15">18th June 2021</td>
<td class="pl-15 pr-15">£48.89</td>
</tr>
<tr>
<td class="pl-15 pr-15">Invoice</td>
<td class="pl-15 pr-15">600055336</td>
<td class="pl-15 pr-15">29th June 2021</td>
<td class="pl-15 pr-15">29th June 2021</td>
<td class="pl-15 pr-15">£601.32</td>
</tr>
<tr>
<td class="pl-15 pr-15">Invoice</td>
<td class="pl-15 pr-15">600055918</td>
<td class="pl-15 pr-15">13th July 2021</td>
<td class="pl-15 pr-15">13th July 2021</td>
<td class="pl-15 pr-15">£72.00</td>
</tr></tbody></table>
" data-original-title="Account Activity Total">
722.21
</a>这将导致以下结果

我需要这些字段只显示innerHTML/value,这样当我单击print时,它不会像这样显示:

发布于 2021-08-09 15:19:47
对于那些一直关注这个帖子的人,我已经了解到了DataTables的光荣的导出选项。
buttons: [{extend: 'print',
exportOptions: {
columns: [ ':visible' ],
format: {
body: function ( data, row, column, node ) {
if (column == 3) {
console.log($(data).text());
return column == 3 ?
$(data).text():
data;
} else if (column == 4) {
return column == 4 ?
$(data).text():
data;
} else if (column == 5) {
return column == 5 ?
$(data).text():
data;
} else if (column == 6) {
return column == 6 ?
$(data).text():
data;
} else if (column == 7) {
return column == 7 ?
$(data).text():
data;
} else if (column == 8) {
return column == 8 ?
$(data).text():
data;
} else if (column == 9) {
return column == 9 ?
$(data).text():
data;
} else {
return data;
}
}
}
},
}],我只能获得将文本嵌入到HTML中的列的文本。我本可以使用循环,但这是项目的变通补丁,所以我相信其他人可以给出更好的结构化答案
https://stackoverflow.com/questions/68649572
复制相似问题