5,276,801 members and growing! (16,617 online)
Email Password   helpLost your password?
Web Development » Client side scripting » General     Intermediate License: The Code Project Open License (CPOL)

Fixed headers in large HTML tables

By Karin Huber

There are quite a lot of ways to fix the header column and rows in HTML tables. But when tables become larger, most of them are not useful because scrolling gets far too slow. In this article, I will show an applicable way for IE.
Javascript, Windows, Visual Studio, IE, Dev

Posted: 24 Jun 2006
Updated: 24 Jun 2006
Views: 50,744
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
19 votes for this Article.
Popularity: 5.33 Rating: 4.17 out of 5
1 vote, 5.3%
1
0 votes, 0.0%
2
2 votes, 10.5%
3
2 votes, 10.5%
4
14 votes, 73.7%
5

Introduction

There are quite a lot of ways to fix the header column and rows in HTML tables. But when tables become larger, most of them are not useful because scrolling gets far too slow. In the following sample, I will show an applicable way for IE.

My HTML page contains two divs and a table.

...
<div id="outerDiv">
 <div id="innerDiv">
  <table>
   ...
  </table>
 </div>
</div>
...

In my sample, the table looks like this (the red border shows the innerDiv):

Sample screenshot

The main idea is to copy the innerDiv with the table three times so that there is a div each for the header row, the header column, the first cell in the header row, and the body of the table.

  • In the first three divs, overflow must be set to hidden.
  • In the body div, overflow can be set to scroll if the body is larger then the available space. Furthermore, the table in the body div needs to be positioned absolutely. Top and Left positions have to be negative (Top = -height of header row, Left = -width of header column) so that the headers are no more visible than the body div.

By copying the whole table, all rows and columns will have equal width and height. If you would only copy the first row of the table to the header div, column width in the header could differ from the body columns. After copying the divs, my outerDiv contains four innerDivs (the red borders show the innerDivs):

Sample screenshot

Finally, the divs have to scroll synchronously. When you scroll to the right, the header row has to move to the right too, and when you scroll to the bottom, the header column needs to move too. I found a nice way to do this here.

Sample screenshot

You can view an online demo here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Karin Huber


Hi, my name is Karin Huber. Since 1998 I have been working as a developer and IT consultant focusing on building database oriented web applications. In 2007 my friend Rainer and I decided that we want to build a business based on COTS (component off-the-shelf) software. As a result we founded "software architects". So today we work as IT consultants and software developers. If you want to know more about our companies or check out my blogs visit http://www.software-architects.com and http://www.cubido.at (German).
Occupation: Software Developer
Company: software architects
Location: Austria Austria

Other popular Client side scripting articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 26 (Total in Forum: 26) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralCheckboxes in Scrollable Tablememberkusseal23:01 3 May '07  
GeneralRe: Checkboxes in Scrollable Tablememberdubbele onzin10:59 29 Oct '07  
JokeFreezing Multiple Columnsmembersivad117815:14 25 Oct '06  
GeneralRe: Freezing Multiple ColumnsmemberHayw1r313:47 26 Nov '07  
GeneralRe: Freezing Multiple Columnsmemberpete in atlanta3:24 17 Dec '07  
Questionwrapping cell textmemberthedrums9:27 16 Oct '06  
GeneralWorking In Most Browsers [modified]memberKenneth Bogert22:02 5 Oct '06  
GeneralWorking in Firefox + IEmemberKenneth BOgert12:45 11 Aug '06  
GeneralRe: Working in Firefox + IEmemberchathuraka20:18 7 Jun '07  
GeneralProblem when using Ctrl-F to findmemberTHEDI19:07 8 Aug '06  
GeneralDisplay row using javascriptmemberadril1qqww7:53 25 Jul '06  
GeneralCopying tablesmemberjasongilley8:44 4 Jul '06  
GeneralRe: Copying tablesmemberDwight Johnson3:56 5 Jul '06  
GeneralRe: Copying tablesmemberKarin Huber8:20 5 Jul '06  
GeneralRe: Copying tablesmemberjasongilley9:51 5 Jul '06  
GeneralRe: Copying tablesmemberKarin Huber4:02 6 Jul '06  
GeneralDuplicating the entire tablememberAshley van Gerven8:20 27 Jun '06  
GeneralRe: Duplicating the entire tablememberKarin Huber6:52 29 Jun '06  
GeneralRe: Duplicating the entire tablememberAshley van Gerven14:43 29 Jun '06