Click here to Skip to main content
15,887,683 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

 
Generalhorizontal scrollbar - solved problem Pin
Boneripper17-Dec-04 1:05
Boneripper17-Dec-04 1:05 
GeneralRe: horizontal scrollbar - solved problem Pin
Anonymous20-May-05 0:28
Anonymous20-May-05 0:28 
GeneralPage Resizing Pin
kitana_q12-Oct-04 8:13
kitana_q12-Oct-04 8:13 
GeneralUsing images in table body Pin
Peter Black16-Sep-04 6:22
Peter Black16-Sep-04 6:22 
GeneralRe: Using images in table body Pin
Peter Black16-Sep-04 6:48
Peter Black16-Sep-04 6:48 
Generalscrollable table with fixed top header and left header Pin
amitas12-Apr-04 1:24
amitas12-Apr-04 1:24 
Generalhi Pin
hongwl94@hotmail.com17-Mar-04 14:56
hongwl94@hotmail.com17-Mar-04 14:56 
GeneralVertical scroll only Pin
aksoo23-Nov-03 22:28
aksoo23-Nov-03 22:28 
GeneralRe: Vertical scroll only Pin
Anonymous16-May-04 23:46
Anonymous16-May-04 23:46 
GeneralRe: Vertical scroll only Pin
ndhai3-Dec-05 6:26
ndhai3-Dec-05 6:26 
Questionhow does one print just that table? Pin
Anonymous12-Nov-03 20:39
Anonymous12-Nov-03 20:39 
AnswerRe: how does one print just that table? Pin
mikeAgent26-May-04 9:16
mikeAgent26-May-04 9:16 
GeneralColumn headers not aligned with table Pin
a_soong11-Nov-03 14:05
a_soong11-Nov-03 14:05 
GeneralRe: Column headers not aligned with table Pin
a_soong11-Nov-03 14:15
a_soong11-Nov-03 14:15 
GeneralRe: Column headers not aligned with table Pin
Brajagopal Bhar14-Jul-04 3:26
Brajagopal Bhar14-Jul-04 3:26 
GeneralRe: Column headers not aligned with table Pin
ndhai3-Dec-05 6:36
ndhai3-Dec-05 6:36 
GeneralInput Data Doubeled Pin
rread10-Oct-03 6:04
rread10-Oct-03 6:04 
GeneralRe: Input Data Doubeled Pin
jeristotle11-Nov-04 7:23
jeristotle11-Nov-04 7:23 
Generalleading blanks in table Pin
Anonymous9-Sep-03 9:05
Anonymous9-Sep-03 9:05 
Questionscrollbar on left? Pin
BillColquhoun9-Sep-03 3:49
BillColquhoun9-Sep-03 3:49 
AnswerRe: scrollbar on left? Pin
Anonymous20-May-05 2:04
Anonymous20-May-05 2:04 
GeneraltHead line up with tBody Pin
brian qing9-Aug-03 19:16
brian qing9-Aug-03 19:16 
GeneralRe: tHead line up with tBody Pin
penguin00121-Feb-05 12:35
susspenguin00121-Feb-05 12:35 
GeneralScrolling Pin
Anonymous27-Jun-03 10:13
Anonymous27-Jun-03 10:13 
GeneralVertical + Horizontal scrolling Pin
samwinfdo27-Apr-03 20:01
samwinfdo27-Apr-03 20:01 

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.