Click here to Skip to main content
15,887,923 members
Articles / Web Development / HTML
Article

Scrollable HTML Table

Rate me:
Please Sign up or sign in to vote.
4.84/5 (55 votes)
6 Sep 2003 405.8K   7.2K   72   65
Make your HTML tables scrollable with this simple method. No additional coding necessary!

Sample Image - Scrollable_Table.jpg

Introduction

This JavaScript code can be used to convert tables in ordinary HTML into scrollable ones. No additional coding is necessary. All you need to do is put header rows in TBODY and give your table an ID field, include the ScrollableTable.js file and call makeScrollableTable in your document's onLoad method.

HTML
<html>
<head>
<script language=JavaScript src=ScrollableTable.js></script>
</head>

<body onload="makeScrollableTable('tabela',true,'auto');">

<table border=0 id=tabela align=center 
  style="border-color: black; border-style: solid; border-width: 1;">
<thead>
<tr>
  <th bgcolor=blue style="color: white" rowspan=2 valign=bottom>ColA</th>
  <th bgcolor=blue style="color: white" colspan=2 align=center>ColBC</th>
  <th bgcolor=blue style="color: white" colspan=2 align=center>ColDE</th>
  <th bgcolor=blue style="color: white" rowspan=2 valign=bottom>ColF</th>
</tr>
<tr>
  <th bgcolor=blue style="color: white">ColB</th>
  <th bgcolor=blue style="color: white">ColC</th>
  <th bgcolor=blue style="color: white">ColD</th>
  <th bgcolor=blue style="color: white">ColE</th>
</tr>
</thead>
<tbody>
<tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td><td>F</td></tr>
<tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td><td>F</td></tr>
<tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td><td>F</td></tr>
<tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td><td>F</td></tr>
<tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td><td>F</td></tr>
<tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td><td>F</td></tr>
<tr>
  <td>A</td>
  <td>BBBBBBBBBBBBBBBBBBBBBBBBB</td>
  <td>C</td>
  <td>D</td>
  <td>E</td>
  <td>F</td>
</tr>
</tbody>
<tfoot>
<tr>
  <td bgcolor=blue style="color: white" colspan=6 align=center>Footer</td>
</tr>
</tfoot>
</table>
</body>
</html>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: vertical + horizontal scrolling Pin
fab_fab128-Apr-03 3:28
fab_fab128-Apr-03 3:28 
GeneralRe: vertical + horizontal scrolling Pin
gladya23-Sep-04 0:12
gladya23-Sep-04 0:12 
QuestionOnly for IE ? Pin
mhe9-Dec-02 21:26
mhe9-Dec-02 21:26 
AnswerRe: Only for IE ? Pin
Wagner DosAnjos10-Dec-02 3:06
Wagner DosAnjos10-Dec-02 3:06 
GeneralRe: Only for IE ? Pin
Jean-Marc Molina10-Dec-02 23:13
Jean-Marc Molina10-Dec-02 23:13 
GeneralRe: Only for IE ? Pin
Anonymous22-Aug-03 7:59
Anonymous22-Aug-03 7:59 
AnswerRe: Only for IE ? Pin
BillBelliveau22-Apr-04 6:34
BillBelliveau22-Apr-04 6:34 
GeneralRe: Only for IE ? Pin
Member 128234917-Aug-04 13:33
Member 128234917-Aug-04 13:33 
The question is not about wasting your time/losing productivity. It is about sticking to the CSS2 specs. Till recently I too used IE. There was an announcement that IE is vulnerable and I am using Mozilla ever since( it even has this tabbed navigation window features which I like very much).
If say atleast 20% of people convert to Mozilla users following a security alert, a business shouldnt lose that 20% of its customers because the javascript developer didn't care about crossbrowser compatibility.

GeneralRe: Only for IE ? Pin
BillBelliveau19-Aug-04 9:42
BillBelliveau19-Aug-04 9:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.