Click here to Skip to main content
6,629,885 members and growing! (20,890 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, Dev
Posted:24 Jun 2006
Views:80,669
Bookmarked:38 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
22 votes for this article.
Popularity: 5.70 Rating: 4.24 out of 5
1 vote, 4.5%
1

2
2 votes, 9.1%
3
2 votes, 9.1%
4
17 votes, 77.3%
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


Member
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 company or check out my blog visit http://www.software-architects.com.
Occupation: Software Developer
Company: software architects
Location: Austria Austria

Other popular Client side scripting articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 35 (Total in Forum: 35) (Refresh)FirstPrevNext
GeneralSupport for Firefox and Chrome PinmemberArne Møller5:51 4 Aug '09  
GeneralFreezing multiple columns PinmemberSøren Christensen23:02 22 Apr '09  
GeneralRe: Freezing multiple columns Pinmemberoxid23:51 2 Jun '09  
GeneralRe: Freezing multiple columns Pinmembercyguard6:05 26 Aug '09  
GeneralDoes anyone have a demo posted somewhere that works on Firefox & Safari? Pinmembertactics233710:05 10 Apr '09  
AnswerRe: Does anyone have a demo posted somewhere that works on Firefox & Safari? Pinmembertactics233713:08 10 Apr '09  
GeneralNot working Pinmembersaulo benigno9:31 28 Jan '09  
QuestionEvents not firing with fixed columns [modified] Pinmembersrinian12:48 30 Sep '08  
GeneralCheckboxes in Scrollable Table Pinmemberkusseal23:01 3 May '07  
GeneralRe: Checkboxes in Scrollable Table Pinmemberdubbele onzin10:59 29 Oct '07  
JokeFreezing Multiple Columns Pinmembersivad117815:14 25 Oct '06  
GeneralRe: Freezing Multiple Columns PinmemberHayw1r313:47 26 Nov '07  
GeneralRe: Freezing Multiple Columns Pinmemberpete in atlanta3:24 17 Dec '07  
GeneralRe: Freezing Multiple Columns PinmemberDavid Barraclough3:52 1 Oct '08  
Questionwrapping cell text Pinmemberthedrums9:27 16 Oct '06  
GeneralWorking In Most Browsers [modified] PinmemberKenneth Bogert22:02 5 Oct '06  
GeneralWorking in Firefox + IE PinmemberKenneth BOgert12:45 11 Aug '06  
GeneralRe: Working in Firefox + IE Pinmemberchathuraka20:18 7 Jun '07  
GeneralProblem when using Ctrl-F to find PinmemberTHEDI19:07 8 Aug '06  
GeneralDisplay row using javascript Pinmemberadril1qqww7:53 25 Jul '06  
GeneralCopying tables Pinmemberjasongilley8:44 4 Jul '06  
GeneralRe: Copying tables PinmemberDwight Johnson3:56 5 Jul '06  
GeneralRe: Copying tables PinmemberKarin Huber8:20 5 Jul '06  
GeneralRe: Copying tables Pinmemberjasongilley9:51 5 Jul '06  
GeneralRe: Copying tables PinmemberKarin Huber4:02 6 Jul '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 Jun 2006
Editor: Smitha Vijayan
Copyright 2006 by Karin Huber
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project