Click here to Skip to main content
15,434,330 members
Articles / Web Development / HTML
Article
Posted 8 Dec 2002

Stats

396.5K views
7.2K downloads
72 bookmarked

Scrollable HTML Table

Rate me:
Please Sign up or sign in to vote.
4.84/5 (55 votes)
6 Sep 2003
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

 
GeneralComplete scrollable table Pin
shahib17-Nov-08 4:56
Membershahib17-Nov-08 4:56 
General"out of stack space" error Pin
mikem4223-Apr-08 9:55
Membermikem4223-Apr-08 9:55 
Generalonly first line aligns correctly - solved Pin
niik26-Sep-07 3:39
Memberniik26-Sep-07 3:39 
QuestionScrollable table with percentage width Pin
SmitaU25-Sep-07 0:33
MemberSmitaU25-Sep-07 0:33 
GeneralChange input value in footer Pin
titus6922-Mar-07 1:11
Membertitus6922-Mar-07 1:11 
GeneralHelp me with Horizontal scroll Pin
manivd29-Nov-06 18:50
Membermanivd29-Nov-06 18:50 
QuestionHow to make scrollbar work dynamic? Pin
abergdavid14-Nov-06 10:13
Memberabergdavid14-Nov-06 10:13 
GeneralScrollbars not displaying with the XHTML DOCTYPE Pin
Rick-N-Roll28-Sep-06 12:19
MemberRick-N-Roll28-Sep-06 12:19 
GeneralScrollable table that dynamically resizes columns -- no need to preset widths for IE Pin
dizzee_rascal18-Jul-06 15:55
Memberdizzee_rascal18-Jul-06 15:55 
GeneralfixTableWidth Problem Pin
Christopher G. Lasater19-Jan-06 6:15
MemberChristopher G. Lasater19-Jan-06 6:15 
QuestionScrollable HTML Table Pin
ndhai3-Dec-05 5:35
Memberndhai3-Dec-05 5:35 
Generalsome table work on javascript Pin
sumeramaz14-Oct-05 7:47
Membersumeramaz14-Oct-05 7:47 
QuestionHow to make horizontal scrolling Pin
sach_oz9-Sep-05 20:53
Membersach_oz9-Sep-05 20:53 
GeneralNo scrollbar in Mozilla and netscape Pin
marine_costal5-Jul-05 10:05
Membermarine_costal5-Jul-05 10:05 
GeneralRe: No scrollbar in Mozilla and netscape Pin
Rohit Joshi23-Feb-07 4:09
MemberRohit Joshi23-Feb-07 4:09 
GeneralRe: No scrollbar in Mozilla and netscape Pin
Terri Layman17-Sep-08 10:09
MemberTerri Layman17-Sep-08 10:09 
GeneralRe: No scrollbar in Mozilla and netscape Pin
frankfry22-Sep-08 3:59
Memberfrankfry22-Sep-08 3:59 
QuestionRe: No scrollbar in Mozilla and netscape Pin
slymen kozaizan8-May-09 2:05
Memberslymen kozaizan8-May-09 2:05 
GeneralRe: No scrollbar in Mozilla and netscape Pin
slamb824-Mar-10 5:04
Memberslamb824-Mar-10 5:04 
Generalprogram not compiling, stops at thead Pin
Lisaleb15-Jun-05 15:00
MemberLisaleb15-Jun-05 15:00 
Questionsorting? Pin
raforaez7-Jun-05 4:22
Memberraforaez7-Jun-05 4:22 
GeneralMozilla Firefox support Pin
Anonymous19-May-05 23:12
MemberAnonymous19-May-05 23:12 
GeneralRe: Mozilla Firefox support Pin
Rohit Joshi23-Feb-07 4:10
MemberRohit Joshi23-Feb-07 4:10 
GeneralNo scrollbar in Mozilla Pin
clairelw23-Mar-05 0:30
Memberclairelw23-Mar-05 0:30 
GeneralRe: No scrollbar in Mozilla Pin
Rohit Joshi23-Feb-07 4:09
MemberRohit Joshi23-Feb-07 4:09 

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.