One solution: have a link to a page that will display only the stuff you want printed, then include the JavaScript stuff on that page to do the printing.
Another solution: add a "print" media type to the page's CSS stylesheet which only displays (prints) the table. E.g., assuming your table has an ID attribute of "fubar":
@media print {
body * {
display: none;
}
table#fubar {
display: table;
}
table#fubar tr {
display: table-row;
}
table#fubar td, table#fubar th {
table-cell;
}
}