gpt4 book ai didi

javascript - CSV、PDF、Excel 文件在数据表的导出扩展中作为 blob 下载

转载 作者:行者123 更新时间:2023-11-30 16:05:50 24 4
gpt4 key购买 nike

我写了一个导出各种格式数据的演示:
HTML 代码:

<div class="container" style="position: relative;top:60px;">
<div class="row">
<table id="empTable" class="display table-bordered" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Designation</th>
<th>Office</th>
<th>Extension</th>
<th>Joining Date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Designation</th>
<th>Office</th>
<th>Extension</th>
<th>Joining Date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
</div>
</div>

Javascript 代码:

var editor;
$('#empTable').dataTable({
dom: 'Bfrtip',
"ajax": "empdata.json",
"columns": [{
"data": "name"
}, {
"data": "designation"
}, {
"data": "office"
}, {
"data": "extension"
}, {
"data": "joining_date"
}, {
"data": "salary"
}],
select: true,
buttons: [
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
],
}]
/*buttons: [{
extend: 'create',
editor: 'myEditor',
formButtons: [{
label: 'cancel',
fn: function() {
this.close();
}
}]
}]*/
});

这是 jsfiddle 链接:https://jsfiddle.net/3x0pa64o/
当我下载各种格式的表格数据时,它下载为 blob,但不是 csvpdfexcel ... 是什么原因?

最佳答案

不确定“它下载为 blob,但不是 csv、pdf、excel”是什么意思。它只是缺少示例中的文件名。

https://datatables.net/extensions/buttons/examples/html5/filename.html 中所述和 https://datatables.net/extensions/buttons/examples/flash/filename.html

默认情况下,由 ... 按钮类型创建的文件的名称将自动取自文档的标题元素。

因此您在 title 元素中设置文件名:

示例:https://jsfiddle.net/qLqugynb/

关于javascript - CSV、PDF、Excel 文件在数据表的导出扩展中作为 blob 下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37067225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com