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 01627514630681812796431138341232471997531117115549540143291997403441411198223741281213308535404907544146905902548469732684867352833751115518642885325342016213185922598046434020407918533793671
Row 16145539816536636704544108159375648114052662910508318205144174131442503315257157564601889400648355381268911642726449029281624757305610952876331293031304601228481460435193141263283230251646
Row 21246196310305027427717772522347136629493512263512675872392345549215302257849724105531894525242085197437444721382205225863858173179248612958303403728243538614041506259013043690474041482991
Row 3341153354353255618798301832128713937643058292033535395871479049962089450811294204410754938188412066295719352388119354124241425149540181900391575438363944567327247271034130045562909584073
Row 425113967234421385626595442719432481974386740557321035793280357549184829557145604675413837681380205755023261308356364453562620145509479016626044489329120744375181313650765961140626447755351
Row 54943408210877221693473320811941707423082116851419437151066548253277490629591065536457172601316779891925664993363333161927496840115289185519877939491932117266561260110001865542618514896
Row 655501752854452024054031267696424882332305214315375280334811271574103146587837604903322627121569377102830704815285647565651286923595919369356944049256336715714229499253742478301757515313920
Row 7476151531321152299351152338573427525321300325640423245552288633593805260917591532573741288657404650341637302366440046751540367842344968141620243116518257116383871319848083947568927714016
Row 8450215703214882318828542839315449112758171615723552312392814755111156486148891641503938405776405330262338265190451411738586641251918902077436235893074165364846474405335251414644265039522839
Row 9509437355382514132139951345388634174612448233382428188971458722552294432659782230186918692955237036432191900364213055810535390327001163491243186274213244486141774504131959821112255810353897
Row 1035252714421928881414470217995563450741083145547388226173970333455264931394429285530540116272759130836723773265817003260345651395499364110885080315925487701585544051615391500250514583627425116
Row 1154363749257240982588521628914414923526159004560274454444664503338179403019121890511754034768127684580128671342341621442407365635625992950173015485949171428224657104422723933779532149203225
Row 12913161927034061667884137827188903830420834844664456017523584564910934154453504363222215522556616839285908547718863273439537881440171720829693782547725024636422266140573442391189246695337
Row 134457483739203141148119715522650379816795061301930881834460243220543442828119840636931548163046875274870333638655249138284938776622555023442439559764798577434874963462800222293215652377
Row 141599215722675622291249133407109520583235390541942532577717772244484245537674696180327363323333754635274149340584053804550841052658204496648028075273123613468518661552223726802096476949835621
Row 152551500525614202230125274922918534661820702553626597442831532308292313422745220199852903903222447435344037943719133352241868183140161077276443071612218835432836413543391632712483843823882
Row 1630094267539134994395252650434543344559493974800300156240052224267795911043888504357633688244149373414731163058741136581415954504262836054118155035784849214354931669567623092579204313293460698
Row 1713744170964415437793351701146040905373359626038584453575328245642327139073261445428413313898488408053894472531020469591547525242674528530881737255154544744143013651247781163611253597
Row 181016339748236051412903144425819245450596310181648118951445621769211939135813430423659014345407482656853806323375458632784588338662040345148233296118234533945886846444138441702130026364109
Row 1941153571135090334847796990550326351324486218933459217848445787309626034153588923235500238512632041451169046361470464711131394242114583079651473147722379005484476149671604126837732693213
Row 204314357014913842623343748152756510052184509490966491143826182583258738364148518421134810615288311623465381322814291697485119962935248574045133949914508244647271805573322212117354431675829
Row 21440176387450469554921179055534699120651622111529039733264803309552001326456614423134310758505655526827134501212171216591766486441982078127810055543327422441472800187610732497128458393824115
Row 221979859232733721994452818003172244237813064499383277645505115471814602424561848036533935262821961437442139081417105416715391229630921008415139644863983202354797305257891581236047640434425
Row 2327749652311918930177951513195307568019515093380123094526251536345333268282657405822596239618684054182559912891796177043663421141211944256442186754492008567734975993297457561684503946495206
Row 2442652013475131942051307830355428196398738774530547311134138517536205640439435123303254754348863303779422652932965973582847033879188042502787122552734942161453372489414443115570453955925244625
Row 252452828171917704804563546524183492739023398581039501476246729062790596638761077249550339345555217542306342440419403517279281313221262742263320273551244358162638175179236730249649564871575
Row 26310350421061575153222845470222001318176331885907305610101142210725431125121415874788104848372725306383658504240146222710499415011270158758761169176726694272164444393588510127094983586430164780
Row 2729115960384243865288368728844836419519037373205943232078258507731950454051631468106626043520477222861626409892714914264465615004143492297432036438322142804636379734811715576414851913888
Row 2812341590430850284770527950165115260625004594465935754586122913224676112221672731226127931572488739235545247025982880387812773120445342673011332857082430437214175242744228382016552238477432681246
Row 2923911369751358044948743416992508442233754114741532397242341344829304716632628508137193928368050014064566495237424956109550762694116170317804383823418214232360417451161640237420145313469628
Row 3018484594225418505747365925562337143355807042637291137415265340449124176348017303277567245359189725455087433516914253109542064173587534864890139612022123101229705676240139462951197914853466
Row 311169957345730008346303882440023331952606683449577840673293204825942511174528477752913648154124952411413643492874103536917461052332258294923379430764344851114852917321015473305834021673
Row 32344758245446531375629273728527150512905317137274080312034413909110647573952248234307128991715432823235321327397056431175186192758777160111874344207675311681527259272922911133545141382758
Row 3312244917829735303791261650308157733908138281222992950165231689584196556921423697502416675211321733896983166144034152401114336636335514543132343259695778422684519942252414071051734633
Row 341207201446182438539417049634714596913483318392741443758388939503217582756782309429759505531343032343064574409584329445130152053505154810345610877040931871525252393514645914978184200952
Row 35131323575201701978397348994913423967105823572094422119972027126613633265346217503915181314405550294339074763471449442223129422294550344895407127567549912651131150895649442069227451601218
Row 36596638245264460284353073626355926289712685574754425229832729112926943595468653233702131553291122291737384384561555554252194483655757804184351944471094250329537775068174546553032191645055699
Row 37119543352042209057853296110333543923722172851253134142418357634033443746773305813411218436925466135122025388190527522444123336322691313918692989498915629773319535255932242701829370722503796
Row 3846181151540244976883474161951664773258646826372133410429924785493965911273624196564325315954017362634131804060563858373334496529884913449346362380593598438625779536140221802254459143706
Row 394893581169830845023421923518056755581220303047255382812593840474525462558901762387799340851303163292835395754829497427983601113239732088413043194443284449715443389565359042643492457541995
Row 4058842607100244864907444536593220457735733584917855006683412245785453508927881442336327203533411089634423019213924925071429828534144415828535735591610424022801741385585949914260192652483265
Row 414686471058064199289331304653332625525101540223454381391858414040561031532447197916558214806261458914941121252391981276652984340684239132564905280322625827556616323930246852404225794655210
Row 422552582434414771543474355860172235634979195339864195190641981940213020863842267338139234687502920668914184475021262548053917286812152044646303407453544804340039369192395866374125634674
Row 4387565544813481359015715343628217935165931335643511969491190140859035859273754125155134448325493703556702686278954061951520951338422290239252101089572626072549391577933434501153015162612
Row 443314178738445565295227746753470379910113327382906456241646314633294710913032399427514761018151320679432211144592154971746397218563891387630164405128516931245112836571731322593411382705
Row 45242257992656339241054142288629707059574521715502610151612347855969417511629369858015477330315136881539588269159452022508616595142132171159447825147269757812913477415931161424410241141731
Row 4648944338446122415233852359413271051449890431604354402232782482120325742015372454125927409944095177221613453897274710473890122240349482212565947263733421051701461538341972605357553518057932789
Row 474072290943131087382716481054286924092734434333412761292183737941309735322349445272014469052824833549760174555895873582171142894720311864339446512375401556231051587122161489437489829061036
Row 4833291472305737531456012753525998551730493722995946561743914040285173413136904082830464915994211595294710541472590838592326706346415945735229521013414483615451736261751395579531545092916
Row 4926164109129623885634167108615195255574635494070245885180385840461760241653623853775420256174131129821751446151012114605432261713078847144103233448254208882330543062772537344901792159771

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.