[autoPrint: false] -- add print button to exported data page
[autoPrint: false] -- add print button to exported data page
rldean1
Posts: 141Questions: 66Answers: 1
I was able to get DT and the 'print' & 'button' extensions to generate a printout. I turned off autoPrint.
Is there a way for me to customize the output, and add a print button that invokes the browser's print functionality? Like, is this a built-in option I could toggle somewhere in the docs? If not, how to I customize the HTML/JS in the output?
$("#tblJobSpecs").DataTable({
dom: 'Bftipr',
responsive: true,
pageLength: 25,
lengthChange: false,
data: jspecs.ary,
columns: [
{ data: 'PosTitle', title: 'Position Title' },
{ data: 'PosCode', title: 'Code' },
{ data: 'Grade', title: 'Grade' },
{ data: 'NewGrade', title: 'FY 19 Grade' },
{ data: 'NewSchedule', title: 'FY 19 Schedule' }
],
buttons: [
{
extend: 'print',
className: 'btn-primary',
text: 'View/print full listing',
autoPrint: false,
title: 'Unified Schedule FY 19 Conversion',
init: function(api, node, config) {
$(node).removeClass('btn-secondary')
}
}
],
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The
customize
callback that is described in theprint
documentation can be used to customise the document to print. If you then want to auto call the browser's print functionality, just remove theautoPrint: false
line.Allan
@allan So I was able to add a button on the output; however, I can't figure out how to get
window.print()
to work from within the output... In my example, if I click the PRINT button, it'll print the main datatable, not the exported table.How do I attache a click listener to the exported document?
Oh I see - you want to trigger printing from a button inside the print view - I hadn't understood that, sorry.
You need to use
win.print()
sincewindow
is the host window.win
is the context for the print view window.Allan