Rohitashv Singhal
Rohitashv Singhal

Reputation: 4557

unable to print borders of table using window.print() function

I am currently working on a wordpress plugin in which I have a table as follow

<table class="responsive display table table-bordered"><tbody><tr><th>Subject</th><th>Total Marks</th><th>Obtained Marks</th></tr><tr><td> 1 . sdf</td><td>99</td><td>20</td></tr><tr><td> 2 . sdf</td><td>23</td><td>30</td></tr><tr><th>Total</th><th>122</th><th>50</th></tr></tbody></table>

This is wrapped in a div print

I am printing this with the following jS

<script>
function print_this()
{
       var divToPrint = document.getElementById('print');
       var popupWin = window.open('', '_blank', 'width=3600,height=500');
       popupWin.document.open();
       popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
       popupWin.document.close();
}
</script>

But whenever I am trying to print it, it does not print any of the table border. How can I print the table borders also :

Upvotes: 0

Views: 1463

Answers (2)

Sela Yair
Sela Yair

Reputation: 284

did you try to use the print CSS. I think it should be easier to set with the CSS what you want to print and then just use

window.print() 

to print it.

Upvotes: 1

harry_beginner
harry_beginner

Reputation: 64

You can use jQuery also. Try it(not tested it.)

$('table.responsive display table table-bordered').css('border','1');

Upvotes: 0

Related Questions