问题描述
我正在使用DataTable v1.10。我在1列中添加了一个隐藏的日期字段以对其进行正确排序。我不希望在导出的文件中找到该隐藏数据,但会在导出的excel / pdf文档中显示该数据。 这是我的代码。
<table id="invoices-table" class="table table-sm table-responsive-md w-100 text-Nowrap">
<thead>
<tr>
<th>Invoice Number</th>
<th>Invoice Type</th>
<th>Invoice Date</th>
<th>Buyer</th>
<th>Status</th>
<th class="doNotExport"></th>
</tr>
</thead>
<tfoot>
<tr>
<th>Invoice Number</th>
<th>Invoice Type</th>
<th>Invoice Date</th>
<th>Buyer</th>
<th></th>
<th class="doNotExport"></th>
</tr>
</tfoot>
</table>
DataTable列的JS代码
colummns =
[
{ data: 'invoiceNumber' },{ data: 'invoiceType' },// here I have added a hidden field because date was not sorting properly.
{ data: 'invoiceDate',render: function (data) { return data === null ? "" : "<span class='d-none'>" + moment(data,'DD/MM/YYYY').format('YYYYMMDD') + "</span>" + data } },{ data: 'dataTransferObject.BuyerDtls.LglNm' },{ data: 'invoiceStatus' },{
data: null,render: function (data) {
return getButton(JSON.stringify(data));
},},]
在视图中,它完全可以正常工作,但是在导出到excel / pdf时,隐藏字段也显示在下面的列中 如果发票日期为02/05/2020,则由于该隐藏元素,它在导出文件中显示为2020050202/05/2020
将提供任何帮助。
解决方法
在数据表上,有一个名为exportOptions
的选项。在该columns: ':visible'
下,如下所示。
buttons: [
{
extend: 'pdfHtml5',exportOptions: {
columns: ':visible'
}
},]