如何自定义jQuery数据表导出,如PDF Excel Print和CSV?

我从数据表使用jQuery数据表。 我想定制这些表格的导出文件插件,如CSV,Excel,PDF和打印button。 如果我打印PDF,它总是在标题中说的jQuery数据表文件导出的标题。 我如何定制? 我也想在导出CSV,PDF和Excel文件时自定义文件名。 我检查了插件中的代码,我看不到导出文件的选项中的代码来定制它。 我是否需要扩展才能下载? 抱歉,我只是新的jQuery数据表。

下面是一个例子 在这里输入图像描述

我怎样才能为PDF,CSV和Excel文件自定义它们? 对不起,编辑不好。

我怎样才能定制正在下载的文件名?

感谢有人能帮忙。

提前致谢。

您可以使用button选项自定义文件名和标题。 除csv button外,所有button都包含用于自定义filenametitle选项。 csv button只有filename选项。

以下是button选项的参考列表:

  • excel选项
  • csv选项
  • pdf选项
  • 打印选项

这是片段。

 $(document).ready(function() { $('#example').DataTable({ dom: 'Bfrtip', buttons: [{ extend: 'pdf', title: 'Customized PDF Title', filename: 'customized_pdf_file_name' }, { extend: 'excel', title: 'Customized EXCEL Title', filename: 'customized_excel_file_name' }, { extend: 'csv', filename: 'customized_csv_file_name' }] }); }); 
 <link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.css" rel="stylesheet" /> <link href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.css" rel="stylesheet" /> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script> <script src="https://cdn.datatables.net/buttons/1.4.2/js/dataTables.buttons.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script> <script src="https://cdn.datatables.net/buttons/1.4.2/js/buttons.html5.min.js"></script> <div class="container"> <table id="example" class="display nowrap" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </thead> <tfoot> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </tfoot> <tbody> <tr> <td>Tiger Nixon</td> <td>System Architect</td> <td>Edinburgh</td> <td>61</td> <td>2011/04/25</td> <td>$3,120</td> </tr> <tr> <td>Garrett Winters</td> <td>Director</td> <td>Edinburgh</td> <td>63</td> <td>2011/07/25</td> <td>$5,300</td> </tr> </tbody> </table> </div>