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 0361366955612931254527603100206306813245605686258329653584930446822154658550098441715944643206414441607174155721575345347489555355533987125023421651518354496475667252153671948516140654351
Row 119855326380646365934567452621445594453075998145611013117898470645631320470829052762174794294162191257640309038425947368115561049555399350812675329037374227330257635715021429552932413122
Row 253422180405031741923829994369228371998154852341959652083491183521364739217856385661466714641073518341804511512470416603722469498646255926327611345449751171118114942402111153574258352201
Row 37294763473534641434393208148172961107047502185372135527119740512113385344003563431214455207386550371143176724017938011163216385125624404199732344554581355022943278416761753346255726145112
Row 4474845445181348459264447389056351892338711372816165236541578221145792911131229741668873860435825471429869336429162405355916035830228373838746458051745471625061063138244963871232531731395087
Row 5449146643226995495117058405851379648764338182822434581375136521077196939921265662080408517973327502034582949504053102908534729913296322327111254344220733873188550329941999608267636246405810
Row 622725869709371911901398287657562632795130727064803160653634045248239133325157666019945347463834193040283657485808225337877208339765694498131984197212219514495224173975519493361413552764323
Row 7968587641954751730497030552017493522534481567384756353245110814494378241551247397433606127916754323506647732340238523643923593024016312337413548421302557931514626549417254020135437034373092
Row 856683151495011304967415212781008330520226451598164447864291139142566441475884541559625344394252996112273826171962682449527783255127654534280260634694182132057915382111118133657882917684
Row 9384636181719246015734065516630042186556038113576467350052244196018171618492733484507316547048342819184814252023042173344511034335587789655776447226305879541040572735211846514210483315004387
Row 1029691884333661841982844388512944374413114983790174841137781730574543773693901481450328593364520363321273391401679542474423533936152137828185115665831428211681190464816961920360245801744525
Row 11325363023365617434217614337827220971488245337225489463564949193708512221712296723664579824143900538256611604696355357821059363911761418974181718240658225420239230183812814967958
Row 12100254831714889376934182342344552451076285231975320327833444861381452835831271455451124559376654448751699179578652193866486330087672904577350259705944135720243349278473058055505503649774904
Row 13154449816238444391917342443994692590635155317144339725492148610043326471342221025918459827144338324256174503155523812598128740032634133046781310681236481716552883279100624634126281920014326
Row 141031395921111065465072644302289392323705993282943046859330057213971409448751833191559596237622550491870488952794105454169533604088176555056982625302142471062153759793804379174939912278
Row 153272159756142115319321097013984509436352465859283055655629558543634296302824103409821395315324569574117546230665990243344312234542741318224402419557022762778194769033122518537518132226529
Row 161927420257221374366395093311102105325052012292159562233430644319056504154859190046964320548059311625437050925892650263598571534613951997366938902417263404718219657502868394150634328
Row 1719171925154426705810158530831307159320916761110215618953910215348001172575436873585463899154492726108926144461418712053906408856534396598756224121392349618035463744345046475520100747802043
Row 18508929021274382151448601907151714802053451944713136227641195042022835632722568945985953634321512235771415322193678369761179533774402241623725829434645844224496379313243931155497612195018
Row 194667431413497801091151414595180440224284442152415193041304516842356535030191232705323538682288123430391628362628155754186415523592888480013082710456710449812577815221852331766159550071541482
Row 201919201610891205160545097173311313039663404592160416353026495840253275013692082428724783454114841461445508623854018164724549227258711102472231362992124050835306621244044764237571426715449
Row 21536713681602913336633741333375531135601355470295715599424978974477731093136177333952185242329395955540258595100809610592690509838914131502438772874289414194555211954424851499630672211
Row 22118353581562309522621333903516106921826171589016774244305639360224784257178046723633525449234069480527456445637384326193112582858301814485418851808247786034512050237353042260448144424684
Row 23307350931696395640651467165291387361215514561936595017454194511616211537994650503419983298277126831065725121323426563953418944921469512591616414090813326498161924744063378492920754786
Row 24249734344382694590136333375541334693041261921115746595586821131617422652311009472424802411255343428033217583419984640301369442054635245559651415122368041425041311346504428527544934955267087
Row 2537542201509251533854109345472514481581599932674324458932004885504429384567402259845681407735512585243228249701743617311718464167372737245582569411083788166610675700427837085705346618923543012
Row 268852523399351634051533654571232187835347403781593012221192346915235050263959323505204853671922484924924503536024101367474528845798416226524082217234383644573343311313260398938354486107759774769
Row 2774292826611649455712682974407927682531253246465455495124143373543146829345864565294027116141355297510664622130356611104315329771318446726383700323242547131573699569124001496562238934338306
Row 281670160413933111156743356955002342300340342318309121143136239519634744156255338667881726477838142144310279141233131318550125857444451955008275177565459223118268506814314986489035631802409
Row 294951418330361173403241254635267346613229229532807391988459918685977112855543557284474232695385127152682267268012342818804099265259453781445818974265605363435144161864166138648223115874283
Row 30411085531147573933341922022428259433694557483819831956360654451175473858032680540460730228643255122043197501734131124414957365378136037494246527923393117459955801060121826372741471325454349
Row 31231440842544926488912961677134642871350503658303590202240593778571443753385383132695884625166208149833321661421588283955312856398457442537195651852432651105549981925841440783142181940822
Row 325873470030735370990516511041013861245178530042618282353204674379910035814112517059934106499910291281490521626202405374530184145150545611104354917614610381545101407483367535801157323850952784
Row 33594255205451530951422447180712402053326233681218875338645913975390177031622849456455394412107157601923270338144383447542377651584975802352634094527147346786281338405450103482118378114301515
Row 343724545377142951233182432831936263653327348929572469264843052074216154982537140617584821373743887718063782785311339455395352320227774911587349242920297330721276540519794631124271356122539
Row 3555762480431817311654256351327813895656231423511285308358411480194856141923355414842963240939843199303224182526397635854881274827035125360814064342242235525625220614025228244130851988529432562293
Row 36511025963431505755395039471553945342201119533557486345754683942256551471221234525835634082140358926211911572679141166971705483144171663121344103766208743915495483123045505877502611287814204
Row 37339355103654258331754907452373471713791850490159027003984268053591691906565551843142238547754431529853763858268756322362772377455411559459748272604393991256326273534342558330412885275395
Row 389202152624474824047564457845291810981885282159320616893595130367438102372270330392989564440181660150641224816404343783051171728134161460116102995301785276225382768555585424178724765861
Row 394613888226153963220572439451104375157625411197348010334954355512922484400948921696572422241640377943627465954448224386705986515447253427277041988243736944922551365222138456321744
Row 40433037962455306439142306433220775143553450102467384043354983579820455825884484374219695748411819453610984502234552923784121814881254496045781163498238771439452540041973542022217256936523646
Row 41356317394834285855745951440015341387337923461271143833971835499758857693360328324354692492911361417314134534662560214933187190849204502247926381113195957222970180549114632567233023119256823494725
Row 421036106728224187290719365884919419655603783295549249135891421439331890145531999924557200328522842254500710943168326810811641171117253644605342337865409422699399325691029513116158672591
Row 43215125288022205102610388495537396054994641214351891740287856892729564630467084989271443142398204149553354591839661701169757163295303920344031539050874842293144175936138767817473461472139563689
Row 442871402521320712635430032171058232238490520321932343325643625251498389424724557994102217062800159459103684461866437732424822548743784001557634903799481847512901439711284762398441219261886
Row 45334521501494515540634689592649173197580399272721914567522115148335760455119193433436753185295408548473167313850547471179200219403301506941338958632650388935843481438918555730758319045924492
Row 462195496677911784030406732441227185948285947231189625562073324347632895171538624996880970322951314734109466924512685524020657004986568147495638505422072161315561123834315991630339018365961
Row 47269411840955105563059054399350211641662267757423593007516456850665369561243653865333935260717093396161525273664570917104761408950042802514414985505379170330491241195282449663396510342439
Row 4825821525252435463444285755571143355796491014483365327715521652986259413913865259618642371111944578582637131139655170362024807702896938168526685759470212123733263610514113891489156456491902
Row 494152617500415012781546166021633552342433733288130344113044687524215244665566758522432079582456501102638378052374598423915384209930272356735675225934733277440192026105552351951414032062713

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.