【问题标题】:I have one excel button and I want add pdf button in data table我有一个 excel 按钮,我想在数据表中添加 pdf 按钮
【发布时间】:2019-08-21 04:43:31
【问题描述】:

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

              }
        ]
    } );
} ); 

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

【问题讨论】:

    标签: javascript php jquery codeigniter datatable


    【解决方案1】:

    您只需要按照本文档提供两个对象。 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>'
    }]
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-25
        • 2015-11-18
        • 2016-05-23
        • 1970-01-01
        • 1970-01-01
        • 2017-06-27
        • 2019-07-07
        • 2018-10-14
        相关资源
        最近更新 更多