数据表打印自定义

时间:2017-01-04 10:34:33

标签: javascript jquery datatables

打印时我的数据表的打印日期在顶部。我想将该日期的格式更改为dd / mm / yy hh:mm。我使用javascript来初始化datatable的标题,但它出现在打印页面的标题中以及表格上方。此外,在打印页面的页脚中,我想显示我的网站名称。我找不到操纵这些的选项。任何帮助,将不胜感激。谢谢。

 $(document).ready(function() {

     var handleDataTableButtons = function() {
         if ($("#report").length) {
             $("#report").DataTable({

                 initComplete: function() {
                     this.api().columns().every(function() {
                         var column = this;
                         var select = $('<select><option value=""></option></select>')
                             .appendTo($(column.footer()).empty())
                             .on('change', function() {
                                 var val = $.fn.dataTable.util.escapeRegex(
                                     $(this).val()
                                 );

                                 column
                                     .search(val ? '^' + val + '$' : '', true, false)
                                     .draw();
                             });

                         column.data().unique().sort().each(function(d, j) {
                             select.append('<option value="' + d + '">' + d + '</option>')
                         });
                     });
                 },
                 dom: "Bfrtip",

                 buttons: [

                     {
                         extend: "excel",
                         className: "btn-sm"
                     },
                     /*    {
                           extend: "pdfHtml5",
                           className: "btn-sm"
                         },*/
                     {
                         extend: "print",
                         className: "btn-sm",
                         message: 'Message',
                         title: 'Some title',
                         customize: function(win) {
                             $(win.document.body).find('table')
                                 .addClass('compact')
                                 .css('font-size', '10pt');
                         }

                     },
                 ],
                 responsive: true
             });
         }
     };

     TableManageButtons = function() {
         "use strict";
         return {
             init: function() {
                 handleDataTableButtons();
             }
         };
     }();

     TableManageButtons.init();

 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<table  id="report">
         <thead>
               <tr>
                   <th>Column1</th>
                   <th>Column2</th>       
               </tr>
          </thead>
          <tbody>
               <tr>
                  <td>Data1</td>
                  <td>Data2</td>
               </tr>
          </tbody>
 </table>

0 个答案:

没有答案