【发布时间】:2021-02-23 05:27:40
【问题描述】:
我正在使用 DataTable v1.10。我在 1 列中添加了一个隐藏的日期字段以对其进行正确排序。我不希望导出文件中的隐藏数据,但它显示在导出的 excel/pdf 文档中。 这是我的代码。
HTML 标记:
<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 代码:
columns =
[
{ 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
我们将不胜感激。
【问题讨论】:
-
你好冈社。重新您的发票日期和隐藏字段导出时如何从列数据中删除隐藏字段?谢谢
标签: javascript jquery datatable momentjs datatables-1.10