Click here to Skip to main content
15,886,032 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.7K   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

 
GeneralHelp me with Horizontal scroll Pin
manivd29-Nov-06 18:50
manivd29-Nov-06 18:50 

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.