Printing data

B

bruce

How can I print formatted data? I am currently using JavaScript AJAX
and creating a table in php from a mysql database. The table is
returned to my webpage.

I know how to print the complete webpage but I don't want the complete
page. I only want the table data to be printed. Every example I found
using Google was printed the complete page. So, either I used the
wrong search parameters or I didn't recognize the example I was
looking for.

Appreciate some help on this one..

Thanks..

Bruce
 
R

Richard Cornford

How can I print formatted data? I am currently using JavaScript
AJAX and creating a table in php from a mysql database. The
table is returned to my webpage.

I know how to print the complete webpage but I don't want the
complete page. I only want the table data to be printed.

That sound like a job for a printer specific style sheet. That is, I
style sheet for use only when printing that hides (usually -
display:none; - ) all of the elements from the HTML page that you do
not want printed (so everything except the table by the sound of
things).
Every example I found using Google was printed the complete
page. So, either I used the wrong search parameters or
I didn't recognize the example I was looking for.

Appreciate some help on this one..

Look up the MEDIA attribute of CSS style sheets (STYLE and LINK
elements), and particularly the 'print' media type. It will probably
also be a good idea to understand the CSS specificity and cascade
rules so that any print style sheet used is efficient.

This is certainly not a javascript question (in that in the few
browser environments where something could be done (e.g. IE, with its
window.onbeforeprint and window.onafterprint events) the CSS approach
would still be considerably easier).

Richard.
 
J

J.R.

How can I print formatted data? I am currently using JavaScript AJAX
and creating a table in php from a mysql database. The table is
returned to my webpage.

I know how to print the complete webpage but I don't want the complete
page. I only want the table data to be printed. Every example I found
using Google was printed the complete page. So, either I used the
wrong search parameters or I didn't recognize the example I was
looking for.

Appreciate some help on this one..

Thanks..

Bruce

Hi,
You might either use a .css file with the media attribute set to "print"
displaying only the table:
<link rel="stylesheet" type="text/css" href="print.css" media="print" />

Or use a .php file / script to generate a .pdf file with only the table.
 
J

Jukka K. Korpela

That sound like a job for a printer specific style sheet.

Yes, it sounds like that.
That is, I
style sheet for use only when printing that hides (usually -
display:none; - ) all of the elements from the HTML page that you do
not want printed (so everything except the table by the sound of
things).

The tricky part might be to isolate the other elements. If the table is
nested deeply in the document tree, it's not trivial.

But assuming that the OP had a reason to post to this group, maybe he
really meant that the normal Print function of a browser should print
the page normally but a page-specific, JavaScript-driven button would
print just the table. At least this sounds like something that might be
reasonable in some circumstances.

I guess this might be best handled using a button with an onclick event
handler that puts the other elements to a class that has display: none
(for media print), calls window.print(), and finally removes the class
from those elements.
 
T

Thomas 'PointedEars' Lahn

Richard said:
Look up the MEDIA attribute of CSS style sheets (STYLE and LINK
elements), and particularly the 'print' media type. It will probably
also be a good idea to understand the CSS specificity and cascade
rules so that any print style sheet used is efficient.

This is certainly not a javascript question (in that in the few
browser environments where something could be done (e.g. IE, with its
window.onbeforeprint and window.onafterprint events) the CSS approach
would still be considerably easier).

Speaking of which: In order to print checkboxes in their current state with
window.print(), we have found it necessary in IE 8 either to force it into
IE 7 Compatibility Mode (with the respective META element) or explicitly
call setAttribute('checked', …) on the checkbox before calling
window.print(). Otherwise the checkbox would be printed in its default
state. We used the `onclick' attribute for that, but if you do nothing else
onclick, the `onbeforeprint' property would probably be better.


PointedEars
 
T

Tom de Neef

bruce said:
How can I print formatted data? I am currently using JavaScript AJAX
and creating a table in php from a mysql database. The table is
returned to my webpage.

I know how to print the complete webpage but I don't want the complete
page. I only want the table data to be printed. Every example I found
using Google was printed the complete page. So, either I used the
wrong search parameters or I didn't recognize the example I was
looking for.
I have a similar case but also want copy facility: a page displays a table,
a chart and a description of the conditions for which the output is valid.
Printing/copying the whole page is not a problem. The problem is to isolate
the table or the chart, together with the description, so it can be printed
or copied.
With javascript I create a new window and copy the relevant elements into
it, then tell the user to print or copy the contents.
This way, I have good control over the layout. Creating a pdf is not an
option since I want to be able to import in excel, powerpoint and word.
Problem with this approach is that the help window is considered a pop-up.
Tom
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top