By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 2,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

printing out a data table as it currently appears

P: n/a
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

Feb 9 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
la***********@zipmail.com wrote:
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>
--
Rob
Feb 10 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.