JS:数据表打印和导出Excel

时间:2018-11-10 07:40:07

标签: javascript printing datatables export

你好,我有一个问题,这可能是新手问题

我的网站上现在有一个数据表,我想将其打印或导出到excel文件中,我遇到的问题是标签<tfoot></tfoot>未包含在打印和导出中

这是我的代码:

JS:

<script type="text/javascript" class="init">
$(document).ready(function() {
  $('#example').DataTable( {
    dom: 'Bfrtip',
    buttons: [
      {
        extend: 'print',
        customize: function ( win ) {
          $(win.document.body)
            .css( 'font-size', '10pt' )
            .prepend(
              '<img src="http://datatables.net/media/images/logo-fade.png" style="position:absolute; top:0; left:0;" />'
            );

          $(win.document.body).find( 'table' )
            .addClass( 'compact' )
            .css( 'font-size', 'inherit' );
        }
      }
    ]
  } );
} );

</script>

1 个答案:

答案 0 :(得分:1)

您可以添加footer: true选项。

// ...
extend: 'print',
footer: true,
// ...

有关更多信息,请查看here