Click here to Skip to main content
15,868,016 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 404.9K   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

 
GeneralSugerence Pin
Anonymous7-Apr-03 0:21
Anonymous7-Apr-03 0:21 
Generalno rows in the table Pin
Member 29814127-Mar-03 23:47
Member 29814127-Mar-03 23:47 
Generalsuperb - thanks! Pin
Member 29814120-Mar-03 5:23
Member 29814120-Mar-03 5:23 
GeneralHorizontal Scrollbar in New WIndow Pin
Anonymous23-Feb-03 17:06
Anonymous23-Feb-03 17:06 
Generalvertical + horizontal scrolling Pin
Ashley van Gerven15-Dec-02 15:52
Ashley van Gerven15-Dec-02 15:52 
GeneralRe: vertical + horizontal scrolling Pin
Wagner DosAnjos16-Dec-02 7:45
Wagner DosAnjos16-Dec-02 7:45 
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 
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.