printing out a data table as it currently appears

L

laredotornado

Hi,

I have a data table on my page (buried amidst other images and
extraneous text). I would like to spawn a new window that
automatically prints the content of my data table, and only that
content. The tricky part is the ordering of the table may not be the
same as when the page was loaded. I recently discovered the virtues
of JQuery and its tablesorter plugin (http://motherrussia.polyester.se/
jquery-plugins/tablesorter/), so it is possible my user will sort the
table rows to his satisfaction before printing.

Your help is greatly appreciated, - Dave
 
R

RobG

Hi,

I have a data table on my page (buried amidst other images and
extraneous text). I would like to spawn a new window that
automatically prints the content of my data table, and only that
content. The tricky part is the ordering of the table may not be the
same as when the page was loaded. I recently discovered the virtues
of JQuery and its tablesorter plugin (http://motherrussia.polyester.se/
jquery-plugins/tablesorter/), so it is possible my user will sort the
table rows to his satisfaction before printing.

Your help is greatly appreciated, - Dave

Have you tried making a clone of the table and putting it into the new
window?

A quick example is below, feature detection etc. has been omitted for
brevity. I'm not sure all browsers will let you move DOM elements
across windows, though I think any that support jQuery will.

If not, wrap the table in a DIV, grab its innerHTML and write that to
the popup (make sure you write the *entire* table if using this method).
You will probably need to add elements for style and script support if
you want the popup to behave like the parent.

<script type="text/javascript">

function popWin () {
var w = window.open('','tableWindow','');
w.document.write('<title>Data table</title><body></body>');
w.document.close();
return w;
}

function popTable(id){
var tableWin = popWin();

// Clone the table and add it to the popup
var table = document.getElementById(id).cloneNode(true);
tableWin.document.body.appendChild(table);
}

</script>
<table id="x"><tr><td>foo<td>bar</table>
<button onclick="popTable('x');">Show table in new window</button>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top