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 031454740446129552813874587143874646521466323056352625611488245716253295513756926935102058291996050342575854573758264456563919777891766472542355498500938320231050107531749742803921268
Row 15252662424449593998477618717095635482949923029397425682749190851594423538428994369935890279026243933450116944627005087329343821977468665730077582505687144124952774347323325929498322384784
Row 237322021754192494138285255278321756043754591713146644540121891222034025124206326631132239116234577431647520641235300357831263106055423677427819703109527845134878374917312771664137114801444
Row 3149023816882811520273940113253467124342651121348843132533200910324593563257492718453406826935611663663234420023364413145401394113402203161739515002396429984025250420674240203341350571945
Row 4575147055303372518735343213491948084216539190810775445561359652695375711052773117226611426363766507640251757423912295724473621805605228435644701530956632925444017612864690182044274787443291
Row 5386856884390290498743434378502921902790506025221292807683178454655753410253141019206849361481138934723597165952062462874539121165498256622155241897587449161305187253837843805590249253985212
Row 6461942184136512598446281322288554803517204824444513122129571730641450284317042635510827174540981101326931161224637328663017417831755510475354644261498136049485107434256211637491533344293376
Row 7565321711850208788631414977102245924608397018962273333215651123602546497644053184155263118973364351544981330278315954225256160314765468373847720949662664827472245511645365823887434739
Row 81774548118296446465147221415305104573941445341555042131360288944734825551054872025565215202760345118419132651387816873583297955976162212565213996792477500928184393273047652863357049632221
Row 93463555538464093362535225270519146793572356284413933264405148545193926457658835871565431585145841290996820846035468428017122390183658002337343653844126673523877454553795902432561851401904
Row 104241241437411725070179153014875945346855211549257920433801587730335757440549011194163247521053097573349181684131580310802613447947344495572333195999622367758794598270748491372422524333391227
Row 11207836221061570166752262087226222841487514620594315445350563395373636993356236412518504686534733934152198270718105214587529434337543889123393468314364727284037193554502841129194757626085836
Row 1215658611723270357575236382724834484225522037081981318719862719748456317142386591012044771298923383923182820847240445519249643511409337840855031567456239704073205519833895325189253084721952
Row 1347022423530304128335274914783275946415674744826330558173647941615223458338483318432949532815454790534523494653245152083432541456785156517812334759292350851998426889214085212460611464757
Row 14235649993957141059823556502797042961216912893329957691931201541536423001537822450919553332192515752685150819795280462813241227104124013288012870463655924224992593818044317193662893915
Row 15148459621053122552191711711433713370846510685282332272557025065219031865968343532450784537196238163142515964327734993628446251991393387145213222214648151807397637921673182150952563882992
Row 16335830862881573050294609447918192501359110345086279277042023307284934092867348377143184299366512941258415955404900225825794261483648023991573130654155891344221032857813431450337493943293717
Row 174932364559381457163558418779655692526025245293587612755673513186736982916394027148424652257921722932258380336343897150124412269431715185576424232493887589626774719400349855224595516553805852
Row 189061120322936424889743871226941281847515140455391380239425255351217056921367792565324653695743550520111828139041514500571934348853665422328562036974175023402846360341293895394357433734
Row 19395380432132738371332363316409311359311480310133931264523671944931121933287244069033732467087625121775142154525357323026168165111021598156958605504431644522816497379915023290493956
Row 201514365219912974420355564376297394104952631894880180119311052486940081075586654761700578826524515270222653959240814891872158252104953330318543585531242881529146332462657582630055269392317624471
Row 2153952226456445931064001435434353321192247797734313039599040054354591120326711841380290423611326246418961361399834515535293354735703160563912882676258628925713107313450851833991396314543532
Row 2248341444953325380831871738234110712682669228631653254396337725927568039181872452144921465691221125691923217424774834251351562481270650331295147615104701214042393125270296656973888314320272854
Row 231940259258524077983229068213602426397378449286593095558162545784581048160850642843881339303555383616413825084058572846530583718124375454924094151597285137644321854868159263855994801
Row 242583411314632880393012531851581140455163090144222685377513435341489426556711027123646462008123745995589291535335122803015245248207453310100326263491497247918458605819283250443009301040142477
Row 25307013240982834985371457512396516643342119311843302070378256096023939167177542631916458961922653816275703930536863423802723329541535151161450342584586454811169235325581553504015861044137
Row 261981539557973167390354793318420148094813850245118002304236848945065251038224075841540427554495560287457593352243217694894214556639075913664325332335725565918035243179413334431326463935693
Row 27135820024439488142432895558355341768112423075815339911235030188415332956350849072491397224491244576174658705539451643797452845355358592908519426552706303416154041864166472715972379305828955747
Row 28477122124621541523401836109824442746668415930915009326129341011289187242774172506925331406404099440933542254575748611079471354041896525655381181472226318551091370390742871630461940313095471
Row 2952417272811591338614620403920785658184819785602480457905442530850392977259115647902457360135032164378180227372303254154422855988374589843559091596228412017452240526238152378193192625185102
Row 3051604594288925332106459359981351394341544690684358925505925369837283955942141439691571832419845964651807175916761331491814661929527044835541660565949383326353313954485221935445777521729825209
Row 311545349851789445639379757824214136829231941326923783197447026825892541379534061481125933234194274362915114808163390582577114997991314766370224703702504833125767213639813806327619234733388
Row 321065665573143261858394556535814422711144232745778309820414168157515631221414934133898174343981940445642351581142516033761344910761179289957375704371623063122351343471740281735765615194524742146
Row 3310535657546892454536786327741351115550515655441728295010429441342814054563114992333850584018912820183358832622331412411714262137329701802575638581723382849042973455524914561630515518321145
Row 3427914241120342873208372115814652036585119132527409304954775782323137275350094410132999249865633569046203400156454252608172363102586356632057265045413916398732553739574139861216262951875264
Row 3580529681063226018745127156915952941111341765445423123417261147784933716502251781122181586530687084381349121211064188829623273351629141601430850515542692027599942582211574101565946183409
Row 36112729395507432031932947255218804206390824459141363540538125651514641895200837555013591514775185841636223253211326502715164429041128181272489243253041370811667857441579363965191559941208
Row 37195045721501154555493991593030301706561657704174917167333504842996300452772547285620994084356414582897425160143634514980147726614467519741934651334901347810774223204445004154246051544441561
Row 3859378269946233263358194827173268425129562759268456244064550056903888374594910142492177012172328554052745917588542094351107512253226609455297373159126837052083362232793443204729871458175
Row 39326828945920503931213715066112640441043356848352729230156014580571239194450507165529395795377178952481098533034034456644250569850423356130541567663569268855335884561136512163110473019545944
Row 40309117224735484247563515272745624024809831919332320832812229449151537317971947466445401580475676018662745176855323501123717191604433285642574412755138721151766414449417793592169215233237
Row 41443712084031202851589555292525116774426348539301153211732970429782368595352822204810613527388286228753677191037435569160540672414229418161024356327819812313399517223499213415267634172912
Row 42675300710254592396822633026679327613931783332551449325876448529795973295259154057305047772641389444563703140213055965178312857622921122930662562905192425443968118516922917138879233265582187
Row 439631549201151323095124119509220434181282018846594490399230729991852537411484311197123841399549134092660551120932452592141123691607443018775460309536020804370345328634243108922933261449999
Row 4447032735625533744685040409255752217317592635123951565440087249555089121077295327819005665267122668725247788324557169580176039521237183510813324222018864605372130971268193092264534
Row 453838344644998146054112808427730332371324937732024236272540062364301855984207919162758813147505794617545220108142136552674414525253464344640292951332831522022279650822316466522455276132039
Row 46167535413649022485343025801618232746123771384399139354229314185573777959487854773916725568653102051889544853894197471912323321208264921784614253235665665650259491234705322258817193779
Row 479165497472459462811423429735451312964284887325916994423362847387443013687376263641933911523838401983518368739171946031715352411730332966210313626306327230642906183595188641012158
Row 4835355243337813474233813148358331918423501714953362534122886942092428550747571452900251222733339205836342144454153782073223218872185857155567042245757925850506132555795620534427411584
Row 4957177241383380554324362668126288337021211125523831685306748925478405945594641838121520827203174214484746463053491246515733518102427425203185335543208471688526945929265633535135421557291

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.