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

时间:2019-08-21 04:43:31

标签: javascript php jquery codeigniter datatable

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>',

              }
        ]
    } );
} ); 

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

2 个答案:

答案 0 :(得分:2)

您只需要根据本文档提供两个对象即可。 here

[{ 
    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>'
}]

答案 1 :(得分:1)

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

$(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>