Locked Table Headers

This is a demo of javascript that allows you to lock the header row and column of an html table. By fixing the headers, it makes browsing through a large table easier. Tested in IE6+, FF2+, Safari3+. Fails in Opera. Using a separate sorter script for table sorting.

Scroll below the table for useable information.

Header
0
Header
1
Header
2
Header
3
Header
4
Header
5
Header
6
Header
7
Header
8
Header
9
Header
10
Header
11
Header
12
Header
13
Header
14
Header
15
Header
16
Header
17
Header
18
Header
19
Header
20
Header
21
Header
22
Header
23
Header
24
Header
25
Header
26
Header
27
Header
28
Header
29
Header
30
Header
31
Header
32
Header
33
Header
34
Header
35
Header
36
Header
37
Header
38
Header
39
Header
40
Header
41
Header
42
Header
43
Header
44
Header
45
Header
46
Header
47
Header
48
Header
49
Row 05293837499256014859289315649893715584140747294827204882112450611127339223751430296838543078446783271448273498450320843787365149043487397734634454730703486258381611353353973460124154454566
Row 15160553967254723462262979367827075183566211373091521354098834736342583555788381853170546941560378258495197133232919830643823573111633669514796556943553851176441488451229041116651996
Row 2169742594943445323075182539327836212009580422743004805254858910743794015281024298733741123357739240751264846580983050143140313197346274533423033135505135180041233563181144410851107390
Row 3438814093973484325383199347351754714055383352315895409629164227552463126601887337425415661830895766107811542637535336664654466318795179307249342535184578737031222387712014881299574847592446
Row 4467844332587192657991565043244940225795523059924690224849701041367119281341522316834103388469232828004201934557529404268111531262167177237482898286715155556329215551064521136903359387455562859
Row 5579866034242678527317293804386310725031848302546161030510418927925276375953025359573429043601986561622050513244457059213339568013203769840207358661073499328754579563538741601114534998324482
Row 63555577213668411768268459822412317623842237533740111214699190757129314042434610725124260746735231437440324612323525019131321362263514928005644597308315256195740394844932602358057282223863
Row 7582549424458249455523103783161432463847851144535945610453822643523478197957414325291201420112695373248493901237105144173785350254756101698263343631334529925498587020232494716505155451174
Row 893443065308436432532409370631142169346540112599313436844729813030588115705724405431147063952713218029381558227217025401147534812843425613019992225649681797249932063569594520413055722375
Row 9936368030637724299411126822334495932551337337313682645240940102272482713263021240758843430432511071126167928812110249137121958445751302615079590326022901985463475973552507161351199727844540
Row 1055603107837545832543424922369256422075293040161025291422560130671047326239894804152827006053626430643674375595912602896429828135996322751534194344544974275103633219923881527236832994811953
Row 11121947091070477186750892325347441349429841563171433221084118465926925257246649448181754310742492179549056854232399011515599565110413252181437506866317055972297517322195695068599033235596
Row 122704106402755375321938363654772669126527011440504923954089285543528716884478359459531215458750499767155853013237441092427495954271406292164885425356572118479419292518465915587520615532
Row 1351449334343582210004277487316691282182560520892582446134829241141291129136281839188219082800527435556164619172339245075005730532554313530584550799702634203544976231949684149146024691586
Row 14285312862888496334644003447613152908162024385460122341335678123564128141412952595845308248415343204333322031309580441085228480323014485123832654043120812451483470413830601820198720341359550
Row 157573428106782320129673334991914521451757784985206241077139135763453625874174591516163500533340893894248972334382293914735450113885906573096327212521534194628101243427034627553217549
Row 1613834242494690335455793490436938713803979254853318341635506517202063463023225068418729645910291280720621350130353283693533416876465125153623825938232723267940607615485216021532695539142
Row 1734154911238623413201103820061916100827192462231953554363318122023637001588467411751994205617512734885714115453053475677312151104836230614271518271935354152394940503924841777164241548571723
Row 18482580745842642877704244639648491845242722292917420674319756283302431661755314231585595997233811648410827023049387114221953264254621416103775388147910773613141553545831995958618
Row 19232743234892616238143691751306238527832881151439463238841400564646265474366523975307171522659421265142421348473453252136152692110530142163486815945786493942174014516156334141203497013683847
Row 20698685323487222413313136482546094598495637052027571817005654445124682288300015053718147632695664123326452701384827559955905751361314133289684824462355802568224795621428170998258704288
Row 21739227353019333979536285953031795474446813841123910843135161329586750633187156044671614227518962230329577540561960455725515693129510732403202613074535265016301356385910951300163332233094
Row 226795822345716073515310910335805597813091159022623126544271635335438566028502507269028892052336932602917831487938683639029573177277528844858600034444694559215634165143429772691487833193133
Row 2356835483119408956184915042402955377934107394710362411514938341734421758977028053046267655924764261847421035359028525717576128693686128430053806412845164847955605516854401077589828634133526
Row 24143622082720379236064972320871617254141323826464974539652693419920545527784011721175942554680560434546235225588723816363639420832671294389947223279498732677721442229276310634355293648482399
Row 25245619852528572144413272750232730372858269126149792473265716544491371195345121927530160948724588203515201767303304462458551904310300749819284437135028005595818473356135276415222853275249
Row 265587206335325110583655134668595530694928997914008197657073118272755842545408920045551648592754705153396533336753587107434014630276012265020178025925122652194426031368404098939599825862309
Row 27371715008892000627108631875583387929801766102228573037170542523226344049759548502012310824312538549137175682544344511559504022127742712582278951980122613845324103327884121216043063874396
Row 28317245981204468156913907318722184416092422026396786364542494245871178358845646396402447801240416345114896469852055662255611172192587957402328510556345940490038761258430558392745255159714354
Row 29446650414336536259423047236549865994537641251814174145197255801441162211321111673659353659831714258292042667571820405235163199176866536381234282851415552202922451204247234381080143626843574
Row 3028504292137422514891510998455478458934355244471051204741574852092767405129914401766208951753151474735335978431678137415569489748303371572126922342350980816512380166411961610376390459301875
Row 31421329082892428346654817176842901732274032512932024425207330694362788395415872430583421442360355153045441015868406152796244067215092313331192214132391059312452545200653195949577529644139
Row 3236073932322723573004284559258093556371542621044096302157244772481958401957273748514118632372915062560572524324633590179836942417542628663374574296029422989116715524363198450894932196412739
Row 334208353143855116546056272165407445062522591535093779294335825491361416491012248932526214483336601821312650439865394166225682430188361158421375750193950927357483199363452794878190620442244
Row 3411831497137856653335485953963969214733013078338727594699943565513737793017291959885951589350107332473243722538115792022350353133401586547983971164341023887581320405859590939965370142744681073
Row 352100412046925304408088051683803226590431702168305946991234127129664488312948348894122220353431015482847712241553250149834779218235001923290256443784240134023812132903220129414323150017224132
Row 3656831584193982933305191491652684020474493224633465940226435118825358406548421501984705582600023694764175329855764131913903403090343311816563526312677834943621191653136324599374854151970
Row 37559873739741615696487021283840307101135244314401355282697515436854393579499180822233710245028017311269440939465456132416753634308512020073244287453972100535557781213504935864038387935675867
Row 3843514718559437274591278921253813766555822703854102614614522719561933022856783409745504458455725601271486145255663341015421305212444961055414533855718041093230435563627554230323879584453945967
Row 391700531130872714699149774363471395224683884305610630981876544630501738445864940492265382458451486993414348343629413975608463385321824357275643675976541127003379220048713848367223261265
Row 404947799513261676140456111223289233184225960133598351283367182187151452031260267731505425527588790266271955481672458726532809734838518954294624142440112084594779610518815927024526
Row 4126234847591343830192891123530043973594017355122513528525227250135837960239019754433239256270412835461502050792140160467812959073134322616875883589411602364219570632751055454306315985309
Row 42132215481442581051884661175937325125553271256371096524120895540025904669469250521884109632753732376759061707142230801324353597941631523586813029171321485445214935216615304312222354548784103
Row 4352715525517319131945334442554333790507952166922709257047963034144955136343474799315153833967312320982551612409330103727381364160136794071385457714601711499187554596454284368512917714309
Row 44242511167896440852564622554463546109502739829176632081069474071018755694488026724430531471461545785716526718614299747470942334514325433451897494044873801399244829172638234495027292325
Row 454322343211701590448726551169353033294561255048092124296821492462480919981159259788422165183247723086199020708905759115163056217882500874596742511984502938845983894441835684378336336634483
Row 465355189145713975120434958631325752410443951431582625442574578848215563192353251471921904349180927945813919528029214644419253442563137132821766163620695176202947251468473932715271300614760
Row 471006503717691141291953340474964111352552321461721153426234363245471581784309721472529176539001172753176847401455202825373241508046811445354496305233001307282196934819911725519595542565781
Row 48510476426629004240239859012687427841442453889343938553372847403724145069745215141601755325134013921624679243336625996211046045333463234732596498211234822438177929544525186837165494070
Row 491606251222792374285842484494400839533903584725612147159611385306516477656514768569021626191035559519941661193923732691466312953873109583922723125383439724175451864436050693351701534457892985

I wrote this script after searching for this functionality, and not finding many existing scripts that could fix both row and column headers, giving the feel of Excel's freeze panes. The scripts I could find were usually part of a bloated grid widget, and typically required definition of the table in JSON or XML, rather than working off of existing HTML markup.

This script works with an existing HTML table. It script assumes your table has one thead with one header tr, and one tbody with multiple tr's.

Useage:

var ts = new tablescroller(tableid,lockonload);
tableid is the ID of your table; lockonload is true/false of whether you want the table to autolock the headers on page load.

Public functions: ts.lock() Locks the headers ts.unlock() Unlocks the headers ts.toggle() Toggles locked/unlocked. Returns corresponding 1 or 0.

Download. This code is released under LGPL

This script has a lot of limitations, and I have to plans to expand it.

See here for another approach using three synced tables.