"Locking" table headers

liunx

Guest
Hi all! I've gone through several threads to find the info I need, without much luck. So, here's the question.<br />
<br />
I need to display tabular output data. The table in question has several columns. Each column has a title. The requirement is to provide a vertical scrollbar if the table becomes too long, keeping the column headers (titles) visible at all times.<br />
<br />
Ideally, I'd like to be able to specify a %age of the available height, so that if the table length exceeds that %age, the scrollbar appears.<br />
<br />
I've tried to implement this using two tables, one for the column headers (titles) and the second table to contain the data. The second table is enclosed in a <DIV> tag w/ "overflow:auto" specified. This approach almost worked. However, when the scrollbar appeared for the second table, the horizontal alignment of the column headers and the column data was messed up.<br />
<br />
BTW, in case it's germane, I'm currently using IE 5.5, since that's the corporate standard for the client.<br />
<br />
Any and all help in this regard will be highly appreciated.<!--content-->You can make the table width 100% of the div and then put the header outside of the div and this way it will be stationary but if its the same length and width it will look like its part of the table I guess. that would be the easyest way that I can think of.<!--content-->Hi PeOfEo! Thanks for your response. That's exactly what I tried. However, it seems that the scrollbar is contained within the width of the DIV. That, in turn, messes up the alignment of the columns. If there's a way to move that scrollbar OUTSIDE the width specified for the DIV, I think things would fall in place. Perhaps some guru here can come up with a solution.<br />
<br />
Have a great day!<br />
<br />
--gemini<!--content-->It might help if you post your code so the rest of us can take a look at it.<!--content-->Hi spufi! I am not able to post the actual code, since client confidentiality comes into play. However, here's some code I created that effectively describes the issue.<br />
<br />
<html><br />
<head><br />
</head><br />
<br />
<body><br />
<br />
<table border="1" cellpadding="2" cellspacing="0" width="98%"><br />
<tr><br />
<td width="20%">Col A</td><br />
<td width="30%">Col B</td><br />
<td>Col C</td><br />
</tr><br />
</table><br />
<br />
<DIV style="overflow:auto; height:400px; width:98%"><br />
<table border="1" cellpadding="2" cellspacing="0" width="100%"><br />
<tr><br />
<td width="20%">11</td><br />
<td width="30%">2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
<tr><br />
<td>11</td><br />
<td>2222</td><br />
<td>333333</td><br />
</tr><br />
</table><br />
</div><br />
<br />
</body><br />
</html><br />
<br />
TIA.<br />
<br />
Have a great day!<!--content-->I see that there isn't a final response here for gemini's question. I'm trying to do the same thing. Although my requirements are to take tabular data and display it while keeping top rows, left columns and bottom row stationary and allowing the other rows to scroll left to right.<br />
<br />
Thoughts?<!--content-->I-frame?<!--content-->Well, I could, but the data in this table is going to be displayed dynamically from the database. With an iframe I'd have to populate the table on different pages. Don't think that will work.<br />
<br />
Even the column headers will be displayed dynamically.<!--content-->Just make the div or the iframe widther then the table and use left alignment so they start in the same place yet the scroll bar is outside of the width of the headers or put The div or iframe inside of the table but put an extra column in that is the width of the scroll bar. Play around with the widths since not all scroll bars in all browsers will be quite the same widths. You could just disable the scroll bars and use a graphical scroll bar using dhtml or something but this is not usually a good alternative since not all browsers can handle that code<!--content-->Check out this page.<br />
<br />
<!-- m --><a class="postlink" href="http://chin.ithsnyc.org/computers/TableHeaderAlwaysVisible.html">http://chin.ithsnyc.org/computers/Table ... sible.html</a><!-- m --><!--content-->Perhaps you can do something with the overflow attribute on the <tbody> tag like this:<br />
<br />
tbody {width:100%; height:200px;overflow:scroll}<br />
<br />
I haven't tested it but in theory that should make the body of the table scrollable while leaving the <thead> and <tfoot> in place.<br />
<br />
The general layout for a table is as follows (since the thead, tfoot, and tbody tags have been left out of the prior discussion):<br />
<br />
<table><thead><br />
table rows for header go here<br />
</thead><tfoot><br />
table rows for footer go here<br />
</tfoot><tbody><br />
table rowsd for body content go here<br />
</tbody></table><!--content-->
 
Back
Top