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 05784526128395393575339153547321513173615607268276822725515395946956791088447644061720270155573455394485758502787439033064640346343054248511130453825386821478347031948151411941113186819992826
Row 1272527938773838379438811832177563147031765851537150685177504852535945562374390408543266734349213412734838132914159965974859525024675335769753094922336923752374023564411929863800509
Row 24387442657001256124479951322270217717448117334836136589336434853235410058255068148416924157360112578256794634531140063616476736452080519346721721430980518738872758585238895303447736162484
Row 3484719863466587911033517374812885999204620992500139759285914297055401678242045644146352348722499156184290464226654456579938553593503502316124401198330885722111429218437571736393459673671491
Row 4550242181016499055631951599219442484448734262587179639435163141527558745135353416661357536735975004385952021320134443775604241219155453421349625235576728635708376310272023278122552102195817411092
Row 533552521439849515425082786535150365315446320664414783518111521988216973114366012894246432605152249151143546159049892701482232273884747472460919992191247554965481630263255045811377025302345
Row 641677565802284057902620594131381115957597131672021652291058541495339525894296533337862429117498754313045517449322641550235321804291308445254972214138653013363686599459315316216355127532639
Row 7592739002865178745490823090414041474718108239382351381347498925924599198223959031435309810213511704522421851887720254427997945216571554535544566040001029117430434177161535548544801
Row 83681384616283242471746150233998542141958026654669321138832413546680312224928225583935391635369033472143582428051878573213801611450018634132552822542848196630451420461654911202906322132021441
Row 914129794603486956185173126240812193896158640775442147128831257584418881039864154616265925017971840458648612191294111010300630453712299671406850174842185015114733728342025732416815434
Row 10156223325422642164415172185952896496616754777170291158831524535430893640472858113393488467027315037681451122124794414572843734307517638632211104235203374374527424402424264355245781141
Row 1143615247553233365696250430702911937230113410351727293507952832434221834925017972452820884308224030894183251359635406271223435458484057213485513172154321118744472361925189499914031746
Row 12210060749915872269848973640231542333175365513643821874166529612736480134953617328652494783568422822753508225933885880555171725115321129336939652954589043361524454591153665081917283526652524
Row 135484917464410604204183142061784177836277102687318871933542290372044784450410721154919573633561206101411945848477223261132326742302512563721555926978447915603474580147421721366029443449692001
Row 14226933301898585639236185144374458875158520155225779137456486042319258116371010391171391513716722760246150520833666196524695971171954372259343288411422638863422331745432266216619743951046
Row 15309123523892498220846403677248211362783298225944699153755244827401120444780233144242414501221822215298131241742373754513551123999118211421168502977517085777211365489348823165337112261261575
Row 164056382539326685512432146915445724205225844058543115647631024440540311861888272751612193152625431058842066494010955656903373817713038187025862568297588665054851935451682478747571092330
Row 172128408331323947187645402251383920192314349446733886730124449410553136565141145933625218794465635321201194141398189758334547580320033837842485567315954817118324252621213644962880259
Row 181027562043402962470555728065793291850232385151159313286302013291974402612502605139923712904550624235750207817441479307628054833530452872212583817086725610353648482816351148741108152029682590
Row 193051690476342025432198432142965144013272130316246584298586553044335112423171072420013531631457047835594576816022336313612252565115175843973695252418474428501137153355585734925492063271415395925
Row 2056415920237513642753260259442703346815974888531824793203475464512052845532762196246041477321447871831135233021548131722136493855539710784490433157452741032264138624132521059433142529965125
Row 2136725583270519922795936246143143794197515161202205746441842468452423714501936357730364567327357152230555326454394367237365711298420135778420753033898110113882878430846655176364688346758831148
Row 22325416023144974594832945333938310633735869360357245286510240102640444439285322745480846495586374624622062319653141254873114339472793416747581614202583218144223140337645712953430259055914
Row 23533676414734937312537342553765088443159616871356116432783688203533552739825396549425462255330663714489324863456210812456888205956461316621889400207622584703671529250481948451729511162802
Row 24411239075710368147171096558922650691211115285434694775443115569926172826303036121733121386431324623310621386241641654183420304401534590251656674299579149336115326205051424602120522143520
Row 25325248025193784245022303833490930613949528750164636489548759615562411625455091260443861727432511755174229399219855692235243069025592881286411686911833096182050024215164211269180251114897
Row 26415954893329321169647333049196432593851193250826483472238725765118359127364751318832472001315241973390122212952106117641843612526650707233314492598732734929172352032878307530453701122054911997
Row 275078534522479254811031435553271315634266593823003450240130771022140530897701721305447552193700309829423612045466425506501817297890129363305353328744249338143982031411730004159460344765349
Row 2848241921206613942666223891725717411283220858163998170259692507253328243140271758671225427334593985663438955612382745146416393501348736113225529744125391771112568318144824818875251653985219
Row 2920015616325975920021355386258210024326232665509429875550179038922679486818090758333994559593949961893525167823985363256920343558883479570257865474573948691380305319013239301623113388
Row 3066420068304881429146571943666347227887433414558239154813257026974033343029523782371217032869530465654431458504559343264464024204038815530214783867449583125203945353588035675444273312375613
Row 31462240314663204522640018781563352555294252487391228743534541931883510146672732114842704337156454042209249610323976122312493529143423523867268625483927322259593436342454983905600298717114262
Row 327116282006418948073209551113007136904636487492563849865519471710994655330714141956130110363085249726285265139420345769439556744495317750643737355318455168142279848223611406336010154445293
Row 332673158858942320748590323662787194034423735828543476518006395168833405352491426893686592213981243338586956061389439061827440541435956581738391632654741394316534551761574714922374674
Row 341783465242550941035181630761517790164526224490150341272949537926302202480541094844065980654348326025544044426551844521197557327543703426862227220870231043321371042541295537202858595571
Row 352831273726231992444810514011115515213814331556974706389420475597164946441772320758585644410576844214903357272431947313064686368631045647961287338842913653365337725763272227987442638024441
Row 3647665118113116193410106042174442512619161893208924443831598910788902759315054318325075967480543963853768222576718311689184529985441355031325813367767326262839379012057111799418756855254649
Row 37242522494090429958543363206910161065108153151745058228614795024204532496884333683408421685233204272371425571336164340104604379571222469365290130030002152199558158746825825866844322
Row 3812744328295215085012287836564262447744415631558111791987301249064089162638764793695355031427862545702974291554922596160942794830442754692610525946613430570312614698764420152344044143556722147
Row 3932345936404077082860293753895338297869134085037533168512195442100749693553430434213312928147457403355872354918174247431238212296112312025179354264393848384944150044534945605534850765524
Row 4028322630429011714751751453550975706339029173895203375751971029335486741622185189546821035147565163925582682979154721199535391795355944939884887473198051804420441626233186406302842643221
Row 41330614533339420592025249038683125320135293708248048232403503618429733173320824145215443395441694410424946992485391318861960469052755024241612796205336802768191811865085438650253557514
Row 422787784384297812563703343142293297299828621751205640155368472126737504830981839213619851674337170018432409403598822781031309258094802274345091471846212117141924327254644335366194831075238
Row 43348218530183703465933295568298416293422160921424112297636278572927203478447675561897464842354398453886859715937468143281913801542334982816438853054076491852362261495146212315452156035764213
Row 4438461530536632381558279389258201666565449189685770270214893223771572136072790318829532474430919685245571127683859390557021858507133102355402315450131561659438245094422279593453813437015496
Row 454346360512142203504928142317874423140586748691982198373748972544138937497540243643196391141324535102766583481742863732191310549164957593930514092430395443491542462455313599283329374213
Row 465978360319983964378390177913324988661114298925352763313954991725586154292687526551672213123424574967510130255664388417683282980444658394502109642303555467832954903369218955285667460044202990
Row 47153172151994283407200211001259347925785661409510521485326634601441372847174402367313023899473612891467709167623333778954669508113294749369759311779196149153260492221230645021377114946944841
Row 48269548462055415927724904247244428215181577696621025593926249011473322326346675358347126673341191307538041292322279138632466558612554952296724553275479746288027392071292439083420218019423440
Row 491795287721485670745125631600517558432840033596159852772707165395759045311400763516237151775295459561768353528641792971387296338883468338248253826296394415447530111626565140335571325

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.