我有一个 excel 按钮,我想在数据表中添加 pdf 按钮



excel按钮正在工作,但是当我添加pdf按钮时,它添加仅显示pdf按钮Excel按钮在pdf按钮添加后隐藏

$(document).ready(function() {
$('#loading_sheet_table').DataTable( {
"paging": false,  
dom: 'Bfrtip',
buttons: [
{ 
extend: 'excel', text: 'export to excel &nbsp; <i class="fa fa-file-excel-o" aria-hidden="true"></i>',
extend: 'pdf',   text: 'export to pdf &nbsp;   <i class="fa fa-file-excel-o" aria-hidden="true"></i>',
}
]
} );
} ); 

如何在数据表中添加两个按钮

您只需要按照本文档给出两个对象。 这里

[{ 
extend: 'excel', text: 'export to excel &nbsp; <i class="fa fa-file-excel-o" aria-hidden="true"></i>'
},
{
extend: 'pdf',   text: 'export to pdf &nbsp;   <i class="fa fa-file-excel-o" aria-hidden="true"></i>'
}]

在这里,您将两个按钮包含在一个对象中。尝试这样。

$(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>Ashley</td>
<td>System Architect</td>
<td>London</td>
<td>61</td>
<td>2011/04/25</td>
<td>$13,120</td>
</tr>
<tr>
<td> Winters</td>
<td>Director</td>
<td>Holland</td>
<td>63</td>
<td>2011/07/25</td>
<td>$52,300</td>
</tr>
</tbody>
</table>
</div>

最新更新