Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
table printing
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Permudious" data-source="post: 479481" data-attributes="member: 55273"><p>Hi all,</p><p></p><p>I was wondering if I can print a table inside HTML, I am able to do a print preview but I can't find where I can add some style.</p><p></p><p>Below my code;</p><p></p><p>I also made a codepen project, which will be easier to view.</p><p></p><p>[URL unfurl="true"]https://codepen.io/Permudious/pen/oNJrwLj[/URL]</p><p></p><p>[CODE=html]<div class="left"></p><p> <div class="divFilterSecond">&#128438; <a onclick="printDiv()">Print list</a></div></p><p></div></p><p><div class="right"></p><p> <table id="table"></p><p> <tr></p><p> <th>Company</th></p><p> <th>Contact</th></p><p> <th>Country</th></p><p> </tr></p><p> <tr></p><p> <td>Alfreds Futterkiste</td></p><p> <td>Maria Anders</td></p><p> <td>Germany</td></p><p> </tr></p><p> <tr></p><p> <td>Centro comercial Moctezuma</td></p><p> <td>Francisco Chang</td></p><p> <td>Mexico</td></p><p> </tr></p><p> <tr></p><p> <td>Ernst Handel</td></p><p> <td>Roland Mendel</td></p><p> <td>Austria</td></p><p> </tr></p><p> <tr></p><p> <td>Island Trading</td></p><p> <td>Helen Bennett</td></p><p> <td>UK</td></p><p> </tr></p><p> <tr></p><p> <td>Laughing Bacchus Winecellars</td></p><p> <td>Yoshi Tannamuri</td></p><p> <td>Canada</td></p><p> </tr></p><p> <tr></p><p> <td>Magazzini Alimentari Riuniti</td></p><p> <td>Giovanni Rovelli</td></p><p> <td>Italy</td></p><p> </tr></p><p> </table></p><p> <iframe name="print_frame" width="0" height="0" frameborder="0" src="about:table"></iframe></p><p></div>[/CODE]</p><p></p><p>[CODE=css].left {</p><p> float: left;</p><p> width: 10%;</p><p> padding: 10px;</p><p> height: 300px;</p><p>} </p><p>.right {</p><p> float: right;</p><p> width: 80%;</p><p> padding: 10px 50px 0px 0px;</p><p> height: 300px;</p><p>}</p><p></p><p>.divFilterSecond {</p><p> background-color: #e9edf0;</p><p> border: none;</p><p> color: black;</p><p> padding: 10px 10px;</p><p> text-decoration: none;</p><p> vertical-align: bottom;</p><p> font-size: 14px;</p><p> width:100%;</p><p>}</p><p></p><p>table {</p><p> font-family: arial, sans-serif;</p><p> border-collapse: collapse;</p><p> width: 100%;</p><p>}</p><p></p><p>td, th {</p><p> border: 1px solid #dddddd;</p><p> text-align: left;</p><p> padding: 8px;</p><p>}</p><p></p><p>tr:nth-child(even) {</p><p> background-color: #dddddd;</p><p>}</p><p></p><p>@media print {</p><p> .inlist {</p><p> color: #000;</p><p> background: #fff;</p><p> }</p><p>}[/CODE]</p><p></p><p>[CODE=javascript]function printDiv() {</p><p> window.frames["print_frame"].document.body.innerHTML = document.getElementById("table").innerHTML;</p><p> window.frames["print_frame"].window.focus();</p><p> window.frames["print_frame"].window.print();</p><p>}[/CODE]</p></blockquote><p></p>
[QUOTE="Permudious, post: 479481, member: 55273"] Hi all, I was wondering if I can print a table inside HTML, I am able to do a print preview but I can't find where I can add some style. Below my code; I also made a codepen project, which will be easier to view. [URL unfurl="true"]https://codepen.io/Permudious/pen/oNJrwLj[/URL] [CODE=html]<div class="left"> <div class="divFilterSecond">🖶 <a onclick="printDiv()">Print list</a></div> </div> <div class="right"> <table id="table"> <tr> <th>Company</th> <th>Contact</th> <th>Country</th> </tr> <tr> <td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Germany</td> </tr> <tr> <td>Centro comercial Moctezuma</td> <td>Francisco Chang</td> <td>Mexico</td> </tr> <tr> <td>Ernst Handel</td> <td>Roland Mendel</td> <td>Austria</td> </tr> <tr> <td>Island Trading</td> <td>Helen Bennett</td> <td>UK</td> </tr> <tr> <td>Laughing Bacchus Winecellars</td> <td>Yoshi Tannamuri</td> <td>Canada</td> </tr> <tr> <td>Magazzini Alimentari Riuniti</td> <td>Giovanni Rovelli</td> <td>Italy</td> </tr> </table> <iframe name="print_frame" width="0" height="0" frameborder="0" src="about:table"></iframe> </div>[/CODE] [CODE=css].left { float: left; width: 10%; padding: 10px; height: 300px; } .right { float: right; width: 80%; padding: 10px 50px 0px 0px; height: 300px; } .divFilterSecond { background-color: #e9edf0; border: none; color: black; padding: 10px 10px; text-decoration: none; vertical-align: bottom; font-size: 14px; width:100%; } table { font-family: arial, sans-serif; border-collapse: collapse; width: 100%; } td, th { border: 1px solid #dddddd; text-align: left; padding: 8px; } tr:nth-child(even) { background-color: #dddddd; } @media print { .inlist { color: #000; background: #fff; } }[/CODE] [CODE=javascript]function printDiv() { window.frames["print_frame"].document.body.innerHTML = document.getElementById("table").innerHTML; window.frames["print_frame"].window.focus(); window.frames["print_frame"].window.print(); }[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
table printing
Top