datatable print complex header print previewLINQ query on a DataTableHow to print a number with commas as thousands separators in JavaScriptPreview an image before it is uploadedHow can I pretty-print JSON using JavaScript?Android get text from htmlHow does Access-Control-Allow-Origin header work?offsetting an html anchor to adjust for fixed headerPrinting with Javascript Preview IssuePrint repeatable multiple header in HTMLdatatable print multiple thead <tr>

What are the problems in teaching guitar via Skype?

Looking after a wayward brother in mother's will

A Mathematical Discussion: Fill in the Blank

Were pen cap holes designed to prevent death by suffocation if swallowed?

Solmization with syllables - du da di

Modern approach to radio buttons

Terminology about G- simplicial complexes

Would an object launched by the Catapult spell do full damage against a Scarecrow?

If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?

The Passive Wisdom (Perception) score of my character on D&D Beyond seems too high

What is the 中 in ダウンロード中?

Comment dit-on « I’ll tell you what » ?

What does it mean when you think without speaking?

What does uniform continuity mean exactly?

Glitch in AC sine wave interfering with phase cut dimming

How is character development a major role in the plot of a story

Why doesn't the Earth's acceleration towards the Moon accumulate to push the Earth off its orbit?

Different PCB color ( is it different material? )

What is the best linguistic term for describing the kw > p / gw > b change, and its usual companion s > h

Infinitely many hats

How current works

What caused the tendency for conservatives to not support climate change reform?

Why does the UK have more political parties than the US?

Draw a checker pattern with a black X in the center



datatable print complex header print preview


LINQ query on a DataTableHow to print a number with commas as thousands separators in JavaScriptPreview an image before it is uploadedHow can I pretty-print JSON using JavaScript?Android get text from htmlHow does Access-Control-Allow-Origin header work?offsetting an html anchor to adjust for fixed headerPrinting with Javascript Preview IssuePrint repeatable multiple header in HTMLdatatable print multiple thead <tr>






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








7















hi im working with datatable and its great but i have problem thats in complex header like this



<thead>
<tr><td>some text</td></tr>
<tr><td>some text</td></tr>
</thead>


now in showing page its like like this
enter image description here
when i hit print preview i gat result like this
enter image description here



that the first tr in thead is gone
i opened datatable.js file and i found this



 var addRow = function ( d, tag ) 
var str = '<tr>';

for ( var i=0, ien=d.length ; i<ien ; i++ )
// null and undefined aren't useful in the print output
var dataOut = d[i] === null

return str + '</tr>';
;

// Construct a table for printing
var html = '<table class="'+dt.table().node().className+'">';

html += '<thead>';

// Adding logo to the page (repeats for every page while print)
if(config.repeatingHead.logo)
var logoPosition = (['left','right','center'].indexOf(config.repeatingHead.logoPosition) > 0) ? config.repeatingHead.logoPosition : 'right';
html += '<tr><th colspan="'+data.header.length+'" style="padding: 0;margin: 0;text-align: '+logoPosition+';"><img style="'+config.repeatingHead.logoStyle+'" src="'+config.repeatingHead.logo+'"/></th></tr>';


// Adding title (repeats for every page while print)
if(config.repeatingHead.title)
html += '<tr><th colspan="'+data.header.length+'">'+config.repeatingHead.title+'</th></tr>';


if ( config.header )
html += addRow( data.header, 'th' );


html += '</thead>';

html += '<tbody>';
for ( var i=0, ien=data.body.length ; i<ien ; i++ )
html += addRow( data.body[i], 'td' );

html += '</tbody>';

if ( config.footer && data.footer )
html += '<tfoot>'+ addRow( data.footer, 'th' ) +'</tfoot>';

html += '</table>';


and its just add the last tr in thead
but i couldn't put the first tr with print preview
thanks a lot



this is a jsfiddle ex
when you preview the table its showing with tow row at thead
but in print preview its showing only on tr in thead



enter link description here










share|improve this question



















  • 4





    Can you please add problem and solution that can be understood?

    – varit05
    Mar 24 at 10:03






  • 2





    Can you create a stack snippet/jsFiddle to verify it?

    – Munim Munna
    Mar 24 at 10:41











  • i upload example on jsfiddle

    – Awar Pulldozer
    Mar 26 at 19:31






  • 1





    @AwarPulldozer Do want exactly header and footer should be in print view right?

    – iyyappan
    Mar 27 at 13:01











  • yes thats what i want

    – Awar Pulldozer
    Mar 27 at 15:39

















7















hi im working with datatable and its great but i have problem thats in complex header like this



<thead>
<tr><td>some text</td></tr>
<tr><td>some text</td></tr>
</thead>


now in showing page its like like this
enter image description here
when i hit print preview i gat result like this
enter image description here



that the first tr in thead is gone
i opened datatable.js file and i found this



 var addRow = function ( d, tag ) 
var str = '<tr>';

for ( var i=0, ien=d.length ; i<ien ; i++ )
// null and undefined aren't useful in the print output
var dataOut = d[i] === null

return str + '</tr>';
;

// Construct a table for printing
var html = '<table class="'+dt.table().node().className+'">';

html += '<thead>';

// Adding logo to the page (repeats for every page while print)
if(config.repeatingHead.logo)
var logoPosition = (['left','right','center'].indexOf(config.repeatingHead.logoPosition) > 0) ? config.repeatingHead.logoPosition : 'right';
html += '<tr><th colspan="'+data.header.length+'" style="padding: 0;margin: 0;text-align: '+logoPosition+';"><img style="'+config.repeatingHead.logoStyle+'" src="'+config.repeatingHead.logo+'"/></th></tr>';


// Adding title (repeats for every page while print)
if(config.repeatingHead.title)
html += '<tr><th colspan="'+data.header.length+'">'+config.repeatingHead.title+'</th></tr>';


if ( config.header )
html += addRow( data.header, 'th' );


html += '</thead>';

html += '<tbody>';
for ( var i=0, ien=data.body.length ; i<ien ; i++ )
html += addRow( data.body[i], 'td' );

html += '</tbody>';

if ( config.footer && data.footer )
html += '<tfoot>'+ addRow( data.footer, 'th' ) +'</tfoot>';

html += '</table>';


and its just add the last tr in thead
but i couldn't put the first tr with print preview
thanks a lot



this is a jsfiddle ex
when you preview the table its showing with tow row at thead
but in print preview its showing only on tr in thead



enter link description here










share|improve this question



















  • 4





    Can you please add problem and solution that can be understood?

    – varit05
    Mar 24 at 10:03






  • 2





    Can you create a stack snippet/jsFiddle to verify it?

    – Munim Munna
    Mar 24 at 10:41











  • i upload example on jsfiddle

    – Awar Pulldozer
    Mar 26 at 19:31






  • 1





    @AwarPulldozer Do want exactly header and footer should be in print view right?

    – iyyappan
    Mar 27 at 13:01











  • yes thats what i want

    – Awar Pulldozer
    Mar 27 at 15:39













7












7








7


3






hi im working with datatable and its great but i have problem thats in complex header like this



<thead>
<tr><td>some text</td></tr>
<tr><td>some text</td></tr>
</thead>


now in showing page its like like this
enter image description here
when i hit print preview i gat result like this
enter image description here



that the first tr in thead is gone
i opened datatable.js file and i found this



 var addRow = function ( d, tag ) 
var str = '<tr>';

for ( var i=0, ien=d.length ; i<ien ; i++ )
// null and undefined aren't useful in the print output
var dataOut = d[i] === null

return str + '</tr>';
;

// Construct a table for printing
var html = '<table class="'+dt.table().node().className+'">';

html += '<thead>';

// Adding logo to the page (repeats for every page while print)
if(config.repeatingHead.logo)
var logoPosition = (['left','right','center'].indexOf(config.repeatingHead.logoPosition) > 0) ? config.repeatingHead.logoPosition : 'right';
html += '<tr><th colspan="'+data.header.length+'" style="padding: 0;margin: 0;text-align: '+logoPosition+';"><img style="'+config.repeatingHead.logoStyle+'" src="'+config.repeatingHead.logo+'"/></th></tr>';


// Adding title (repeats for every page while print)
if(config.repeatingHead.title)
html += '<tr><th colspan="'+data.header.length+'">'+config.repeatingHead.title+'</th></tr>';


if ( config.header )
html += addRow( data.header, 'th' );


html += '</thead>';

html += '<tbody>';
for ( var i=0, ien=data.body.length ; i<ien ; i++ )
html += addRow( data.body[i], 'td' );

html += '</tbody>';

if ( config.footer && data.footer )
html += '<tfoot>'+ addRow( data.footer, 'th' ) +'</tfoot>';

html += '</table>';


and its just add the last tr in thead
but i couldn't put the first tr with print preview
thanks a lot



this is a jsfiddle ex
when you preview the table its showing with tow row at thead
but in print preview its showing only on tr in thead



enter link description here










share|improve this question
















hi im working with datatable and its great but i have problem thats in complex header like this



<thead>
<tr><td>some text</td></tr>
<tr><td>some text</td></tr>
</thead>


now in showing page its like like this
enter image description here
when i hit print preview i gat result like this
enter image description here



that the first tr in thead is gone
i opened datatable.js file and i found this



 var addRow = function ( d, tag ) 
var str = '<tr>';

for ( var i=0, ien=d.length ; i<ien ; i++ )
// null and undefined aren't useful in the print output
var dataOut = d[i] === null

return str + '</tr>';
;

// Construct a table for printing
var html = '<table class="'+dt.table().node().className+'">';

html += '<thead>';

// Adding logo to the page (repeats for every page while print)
if(config.repeatingHead.logo)
var logoPosition = (['left','right','center'].indexOf(config.repeatingHead.logoPosition) > 0) ? config.repeatingHead.logoPosition : 'right';
html += '<tr><th colspan="'+data.header.length+'" style="padding: 0;margin: 0;text-align: '+logoPosition+';"><img style="'+config.repeatingHead.logoStyle+'" src="'+config.repeatingHead.logo+'"/></th></tr>';


// Adding title (repeats for every page while print)
if(config.repeatingHead.title)
html += '<tr><th colspan="'+data.header.length+'">'+config.repeatingHead.title+'</th></tr>';


if ( config.header )
html += addRow( data.header, 'th' );


html += '</thead>';

html += '<tbody>';
for ( var i=0, ien=data.body.length ; i<ien ; i++ )
html += addRow( data.body[i], 'td' );

html += '</tbody>';

if ( config.footer && data.footer )
html += '<tfoot>'+ addRow( data.footer, 'th' ) +'</tfoot>';

html += '</table>';


and its just add the last tr in thead
but i couldn't put the first tr with print preview
thanks a lot



this is a jsfiddle ex
when you preview the table its showing with tow row at thead
but in print preview its showing only on tr in thead



enter link description here







javascript html datatable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 19:31







Awar Pulldozer

















asked Mar 22 at 7:13









Awar PulldozerAwar Pulldozer

283423




283423







  • 4





    Can you please add problem and solution that can be understood?

    – varit05
    Mar 24 at 10:03






  • 2





    Can you create a stack snippet/jsFiddle to verify it?

    – Munim Munna
    Mar 24 at 10:41











  • i upload example on jsfiddle

    – Awar Pulldozer
    Mar 26 at 19:31






  • 1





    @AwarPulldozer Do want exactly header and footer should be in print view right?

    – iyyappan
    Mar 27 at 13:01











  • yes thats what i want

    – Awar Pulldozer
    Mar 27 at 15:39












  • 4





    Can you please add problem and solution that can be understood?

    – varit05
    Mar 24 at 10:03






  • 2





    Can you create a stack snippet/jsFiddle to verify it?

    – Munim Munna
    Mar 24 at 10:41











  • i upload example on jsfiddle

    – Awar Pulldozer
    Mar 26 at 19:31






  • 1





    @AwarPulldozer Do want exactly header and footer should be in print view right?

    – iyyappan
    Mar 27 at 13:01











  • yes thats what i want

    – Awar Pulldozer
    Mar 27 at 15:39







4




4





Can you please add problem and solution that can be understood?

– varit05
Mar 24 at 10:03





Can you please add problem and solution that can be understood?

– varit05
Mar 24 at 10:03




2




2





Can you create a stack snippet/jsFiddle to verify it?

– Munim Munna
Mar 24 at 10:41





Can you create a stack snippet/jsFiddle to verify it?

– Munim Munna
Mar 24 at 10:41













i upload example on jsfiddle

– Awar Pulldozer
Mar 26 at 19:31





i upload example on jsfiddle

– Awar Pulldozer
Mar 26 at 19:31




1




1





@AwarPulldozer Do want exactly header and footer should be in print view right?

– iyyappan
Mar 27 at 13:01





@AwarPulldozer Do want exactly header and footer should be in print view right?

– iyyappan
Mar 27 at 13:01













yes thats what i want

– Awar Pulldozer
Mar 27 at 15:39





yes thats what i want

– Awar Pulldozer
Mar 27 at 15:39












2 Answers
2






active

oldest

votes


















1





+50









You asked for a work-around and since it is already mentioned not a feature for Datatables at the moment. You could simply convert it to a PDF through grabbing only the tables contents. Then add styling for the print window without any libraries. It really is just a window.



It is just a matter of injecting the right style before loading the window. So we just need to make sure we grab the style outputted by datatables and inject that.



enter image description here




CSS




 table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;
table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;




HTML




<div id="print-window">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th rowspan="2">Name</th>
<th colspan="2">HR Information</th>
<th colspan="3">Contact</th>
</tr>
<tr>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>$320,800</td>
<td>Edinburgh</td>
<td>5421</td>
<td>t.nixon@datatables.net</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>$170,750</td>
<td>Tokyo</td>
<td>8422</td>
<td>g.winters@datatables.net</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>$86,000</td>
<td>San Francisco</td>
<td>1562</td>
<td>a.cox@datatables.net</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>$433,060</td>
<td>Edinburgh</td>
<td>6224</td>
<td>c.kelly@datatables.net</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</tfoot>
</table>
</div>
<input type="button" value="Print" onclick="pdf()" />



Javascript




function pdf() 
let t = document.getElementById('print-window').innerHTML;

let style = "<style>";
style = style + "table width: 100%; font-size: 17px;";
style = style + "table, th, td border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: center;";
style = style + "</style>";
let win = window.open('', '', 'height=700,width=700');

win.document.write('<html><head>');
win.document.write('<title>Profile</title>');
win.document.write(style);
win.document.write('</head>');
win.document.write('<body>');
win.document.write(t);
win.document.write('</body></html>');

win.document.close();
win.print();






share|improve this answer

























  • thanks man after all i changed to bootstrap-table.com bc when your report is 50 page and more making pdf and put data inside tack much time i guess bootstrap-table is much easer to use but i guess a lot of people search about this solution

    – Awar Pulldozer
    Mar 30 at 10:29


















3














As discussed in this topic from Datatables website, this feature is not yet available.






share|improve this answer























  • i know that but i ask if anyone can fix it here

    – Awar Pulldozer
    Mar 29 at 15:31











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294594%2fdatatable-print-complex-header-print-preview%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1





+50









You asked for a work-around and since it is already mentioned not a feature for Datatables at the moment. You could simply convert it to a PDF through grabbing only the tables contents. Then add styling for the print window without any libraries. It really is just a window.



It is just a matter of injecting the right style before loading the window. So we just need to make sure we grab the style outputted by datatables and inject that.



enter image description here




CSS




 table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;
table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;




HTML




<div id="print-window">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th rowspan="2">Name</th>
<th colspan="2">HR Information</th>
<th colspan="3">Contact</th>
</tr>
<tr>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>$320,800</td>
<td>Edinburgh</td>
<td>5421</td>
<td>t.nixon@datatables.net</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>$170,750</td>
<td>Tokyo</td>
<td>8422</td>
<td>g.winters@datatables.net</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>$86,000</td>
<td>San Francisco</td>
<td>1562</td>
<td>a.cox@datatables.net</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>$433,060</td>
<td>Edinburgh</td>
<td>6224</td>
<td>c.kelly@datatables.net</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</tfoot>
</table>
</div>
<input type="button" value="Print" onclick="pdf()" />



Javascript




function pdf() 
let t = document.getElementById('print-window').innerHTML;

let style = "<style>";
style = style + "table width: 100%; font-size: 17px;";
style = style + "table, th, td border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: center;";
style = style + "</style>";
let win = window.open('', '', 'height=700,width=700');

win.document.write('<html><head>');
win.document.write('<title>Profile</title>');
win.document.write(style);
win.document.write('</head>');
win.document.write('<body>');
win.document.write(t);
win.document.write('</body></html>');

win.document.close();
win.print();






share|improve this answer

























  • thanks man after all i changed to bootstrap-table.com bc when your report is 50 page and more making pdf and put data inside tack much time i guess bootstrap-table is much easer to use but i guess a lot of people search about this solution

    – Awar Pulldozer
    Mar 30 at 10:29















1





+50









You asked for a work-around and since it is already mentioned not a feature for Datatables at the moment. You could simply convert it to a PDF through grabbing only the tables contents. Then add styling for the print window without any libraries. It really is just a window.



It is just a matter of injecting the right style before loading the window. So we just need to make sure we grab the style outputted by datatables and inject that.



enter image description here




CSS




 table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;
table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;




HTML




<div id="print-window">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th rowspan="2">Name</th>
<th colspan="2">HR Information</th>
<th colspan="3">Contact</th>
</tr>
<tr>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>$320,800</td>
<td>Edinburgh</td>
<td>5421</td>
<td>t.nixon@datatables.net</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>$170,750</td>
<td>Tokyo</td>
<td>8422</td>
<td>g.winters@datatables.net</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>$86,000</td>
<td>San Francisco</td>
<td>1562</td>
<td>a.cox@datatables.net</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>$433,060</td>
<td>Edinburgh</td>
<td>6224</td>
<td>c.kelly@datatables.net</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</tfoot>
</table>
</div>
<input type="button" value="Print" onclick="pdf()" />



Javascript




function pdf() 
let t = document.getElementById('print-window').innerHTML;

let style = "<style>";
style = style + "table width: 100%; font-size: 17px;";
style = style + "table, th, td border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: center;";
style = style + "</style>";
let win = window.open('', '', 'height=700,width=700');

win.document.write('<html><head>');
win.document.write('<title>Profile</title>');
win.document.write(style);
win.document.write('</head>');
win.document.write('<body>');
win.document.write(t);
win.document.write('</body></html>');

win.document.close();
win.print();






share|improve this answer

























  • thanks man after all i changed to bootstrap-table.com bc when your report is 50 page and more making pdf and put data inside tack much time i guess bootstrap-table is much easer to use but i guess a lot of people search about this solution

    – Awar Pulldozer
    Mar 30 at 10:29













1





+50







1





+50



1




+50





You asked for a work-around and since it is already mentioned not a feature for Datatables at the moment. You could simply convert it to a PDF through grabbing only the tables contents. Then add styling for the print window without any libraries. It really is just a window.



It is just a matter of injecting the right style before loading the window. So we just need to make sure we grab the style outputted by datatables and inject that.



enter image description here




CSS




 table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;
table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;




HTML




<div id="print-window">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th rowspan="2">Name</th>
<th colspan="2">HR Information</th>
<th colspan="3">Contact</th>
</tr>
<tr>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>$320,800</td>
<td>Edinburgh</td>
<td>5421</td>
<td>t.nixon@datatables.net</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>$170,750</td>
<td>Tokyo</td>
<td>8422</td>
<td>g.winters@datatables.net</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>$86,000</td>
<td>San Francisco</td>
<td>1562</td>
<td>a.cox@datatables.net</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>$433,060</td>
<td>Edinburgh</td>
<td>6224</td>
<td>c.kelly@datatables.net</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</tfoot>
</table>
</div>
<input type="button" value="Print" onclick="pdf()" />



Javascript




function pdf() 
let t = document.getElementById('print-window').innerHTML;

let style = "<style>";
style = style + "table width: 100%; font-size: 17px;";
style = style + "table, th, td border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: center;";
style = style + "</style>";
let win = window.open('', '', 'height=700,width=700');

win.document.write('<html><head>');
win.document.write('<title>Profile</title>');
win.document.write(style);
win.document.write('</head>');
win.document.write('<body>');
win.document.write(t);
win.document.write('</body></html>');

win.document.close();
win.print();






share|improve this answer















You asked for a work-around and since it is already mentioned not a feature for Datatables at the moment. You could simply convert it to a PDF through grabbing only the tables contents. Then add styling for the print window without any libraries. It really is just a window.



It is just a matter of injecting the right style before loading the window. So we just need to make sure we grab the style outputted by datatables and inject that.



enter image description here




CSS




 table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;
table

width: 300px;
font-size: 17px;

table, th, td

border: solid 1px #DDD;
border-collapse: collapse;
padding: 2px 3px;
text-align: center;




HTML




<div id="print-window">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th rowspan="2">Name</th>
<th colspan="2">HR Information</th>
<th colspan="3">Contact</th>
</tr>
<tr>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>$320,800</td>
<td>Edinburgh</td>
<td>5421</td>
<td>t.nixon@datatables.net</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>$170,750</td>
<td>Tokyo</td>
<td>8422</td>
<td>g.winters@datatables.net</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>$86,000</td>
<td>San Francisco</td>
<td>1562</td>
<td>a.cox@datatables.net</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>$433,060</td>
<td>Edinburgh</td>
<td>6224</td>
<td>c.kelly@datatables.net</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Office</th>
<th>Extn.</th>
<th>E-mail</th>
</tr>
</tfoot>
</table>
</div>
<input type="button" value="Print" onclick="pdf()" />



Javascript




function pdf() 
let t = document.getElementById('print-window').innerHTML;

let style = "<style>";
style = style + "table width: 100%; font-size: 17px;";
style = style + "table, th, td border: solid 1px #DDD; border-collapse: collapse;";
style = style + "padding: 2px 3px;text-align: center;";
style = style + "</style>";
let win = window.open('', '', 'height=700,width=700');

win.document.write('<html><head>');
win.document.write('<title>Profile</title>');
win.document.write(style);
win.document.write('</head>');
win.document.write('<body>');
win.document.write(t);
win.document.write('</body></html>');

win.document.close();
win.print();







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 29 at 22:50

























answered Mar 29 at 22:09









RaymondRaymond

1,115415




1,115415












  • thanks man after all i changed to bootstrap-table.com bc when your report is 50 page and more making pdf and put data inside tack much time i guess bootstrap-table is much easer to use but i guess a lot of people search about this solution

    – Awar Pulldozer
    Mar 30 at 10:29

















  • thanks man after all i changed to bootstrap-table.com bc when your report is 50 page and more making pdf and put data inside tack much time i guess bootstrap-table is much easer to use but i guess a lot of people search about this solution

    – Awar Pulldozer
    Mar 30 at 10:29
















thanks man after all i changed to bootstrap-table.com bc when your report is 50 page and more making pdf and put data inside tack much time i guess bootstrap-table is much easer to use but i guess a lot of people search about this solution

– Awar Pulldozer
Mar 30 at 10:29





thanks man after all i changed to bootstrap-table.com bc when your report is 50 page and more making pdf and put data inside tack much time i guess bootstrap-table is much easer to use but i guess a lot of people search about this solution

– Awar Pulldozer
Mar 30 at 10:29













3














As discussed in this topic from Datatables website, this feature is not yet available.






share|improve this answer























  • i know that but i ask if anyone can fix it here

    – Awar Pulldozer
    Mar 29 at 15:31















3














As discussed in this topic from Datatables website, this feature is not yet available.






share|improve this answer























  • i know that but i ask if anyone can fix it here

    – Awar Pulldozer
    Mar 29 at 15:31













3












3








3







As discussed in this topic from Datatables website, this feature is not yet available.






share|improve this answer













As discussed in this topic from Datatables website, this feature is not yet available.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 8:14









WR.WR.

1264




1264












  • i know that but i ask if anyone can fix it here

    – Awar Pulldozer
    Mar 29 at 15:31

















  • i know that but i ask if anyone can fix it here

    – Awar Pulldozer
    Mar 29 at 15:31
















i know that but i ask if anyone can fix it here

– Awar Pulldozer
Mar 29 at 15:31





i know that but i ask if anyone can fix it here

– Awar Pulldozer
Mar 29 at 15:31

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294594%2fdatatable-print-complex-header-print-preview%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현