CSV,PDF,Excel文件在数据表的导出扩展中作为块下载
我写了一个演示,以各种格式导出数据:
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
下载,但不是以csv
, pdf
, excel
…原因是什么?
不知道你的意思是“它下载为blob,但不是csv,pdf,excel”。 它只是在你的例子中缺less文件名。
默认情况下,由…buttontypes创build的文件的名称将自动从文档的标题元素中获取。
所以你在title
元素中设置文件名:
例如: https : //jsfiddle.net/qLqugynb/