How do you create scrollable tables in HTML? I've tried placing the TBODY section in a DIV and setting "overflow-y: scroll." This works until the user prints the page, when only the visible area of the table is printed. Is this the only way or the preferred method for creating scrollable tables? If not, what is the preferred method and if so, how can I print the entire table? I've tried using "@media print" in the style sheet to override the overflow attribute, but the attribute is not inherited from the CSS.
Also, if at all possible, I would like to keep this in a single table with fixed headers so that I may use "display:table-header-group" to print the header at the top of each subsequent page.
<html>
<head>
<script language="javascript">
window.onload = init;
function init()
{
var eTable = document.getElementById("headers");
eTable.style.setExpression("width","document.all.data.offsetWidth");
}
</script>
<style>
table#headers, table#data {table-layout:fixed;background:#dda0dd;}
td, th {vertical-align:top;background:#ffffff;}
</style>
</head>
<body>
<table cellpadding="4" cellspacing="1" id="headers">
<col width="20%">
<col width="20%">
<col width="20%">
<col width="20%">
<tr>
<th>Test</th>
<th>bunk</th>
<th>burp</th>
<th>Hmm</th>
</tr>
</table>
<div style="width:100%;height:300px;overflow-y:auto;">
<table cellpadding="4" cellspacing="1" width="100%" id="data">
<col width="20%">
<col width="20%">
<col width="20%">
<col width="20%">
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
<tr>
<td>blah</td>
<td>bunk</td>
<td>to be or not to be</td>
<td>burp</td>
</tr>
</table>
</div>
</body>
</html>
I can't use IFrames (I don't want to put the table building logic in a separate page). The second solution works (this is the solution I had before), but doesn't satisfy the printing requirements. I wrote a function to be called from the onBeforePrint and onAfterPrint events of the body to toggle the overflow between auto and visible. This will allow the entire table to be printed instead of just the area visible on the screen. I still would like to be able to have a single table containing the header and the elements so that if the table spans multiple pages when printed, the header will appear at the top of each page. Is this possible?
Whatever is generating the table in the main page does not have to generate the table again in the child window -- it's already there in the opener window. So, if this is a big table, or you are using ASP / SQL to generate the table, then an added bonus with the innerHTML method is no waiting for the table to be regenerated!
I have an extremely simple way of doing it.
You can see it in action at http://ufo.gamerzcore.com/
<iframe src="html file.htm" scrolling="yes" >
</iframe>
Extremely simple. And i love it.
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.
<note>
Unless it is clear to me that the question has been answered I will recommend delete. It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>
<HTML>
<BODY>
<CENTER>
<TABLE border='1' cellpadding='1' cellspacing='1'>
<TR>
<TH width='160' nowrap>Heading 1</th>
<TH width='160' nowrap>Heading 2</th>
<TH width='160' nowrap>Heading 3</th>
<TH width='160' nowrap>Heading 4</th>
<TH width='15' comment='this is the scrollbar spacer'> </th>
</tr>
<TR>
<TD colspan='5'><IFRAME name='myIFrame' id='myIFrame' src='myTable.htm' width='100%' height='123' border='0' frameborder='0' marginwidth='0' marginheight='0' ></iframe></td>
</tr>
<TR>
<TH>Footer 1</th>
<TH>Footer 2</th>
<TH>Footer 3</th>
<TH>Footer 4</th>
<TH> </th>
</tr>
</table>
</center>
</body>
</html>