简体   繁体   中英

How do I add element to be printed using dataTable print button?

I use DataTable print button to print files. I'd like to add another div to be printed above or under the table.

I use this script in datatable to add some header

title : "This should be another element printed above the DataTable<br /><span id='txt-small' style='font-size:'12px !important;'>Dates : </span>",

But, it's probably not the right method because I may add a complex header above the DataTable.

I also use footer : true, to add something to print in <tfoot> but then again I may add a complex footer under the DataTable.

So, how do I add another element div or table to be printed above or under the DataTable when I print the table?

You can use the customize method:

{
  extend: 'print',
  title: ' ',
  message: ' ',
  customize: function(win) {
    $(win.document.body).append('<html elements here>'); //after the table
    $(win.document.body).prepend('<html elements here>'); //before the table
  }
},

Reference here : Customisation of the print view window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM