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 0275830246671822253246463048566541635480262458572469301241379353183460619975941424719312382358368456011788272328602952529714864253575170761410335375413351175773466859693835113926575245910
Row 1379650413407167053711326761297326714605793285759212239415850623222978946264270621813601187732431161171235942834199031333143209274553502487425034735013567112855288406229665654458823038565313
Row 2575327111912898491936661481121297017955940294433793747449836805538177140677649232983582947323403364516402557289121044282872177764021465526255742421823997110954662405221645951543424828363909
Row 34326255135234504277954912161384147213283147894265413791512575169119314232604024592990252922533831341055795810215729891150332811931913272534663505481193166046458483404234985845219171695
Row 43524040273732382499246834092182536531895844931207415164253697132751470590239853579293746542088517038402818526927044481755245812865364323652882509272409946915184477466544102992425535372637
Row 5492333675657442425521371506943016923229539418173990549232204798503026148071397593917093436938420691599134854161136185012095913925179636443428365433483891359317195233244746295745343332101890
Row 653312943380356209385695178056455197360853034448172559031165549566631963965245341923114423937376233865911520638727744318262246585545590724319211232741517253020562140501327563656110932684715
Row 714993267567813102110708382731444629467137273429561651441683442027833680167751241722355715793433585350233323246011215314133268756131168553234123125277251857511273885385514542165754196739104565
Row 8133947733903349452932572232557887784881164548851380335415661134330047564546640125393023448574839622014274933373201482514982661310857487114250446447942715487344729515117583524889219073481
Row 95750596230971304726138531584145514658444355168463448783362427024054525557131840552018368027423447971508459973668208643774153127955181781802185218714489540750531157408416085078596937554678
Row 105454255048842436330920302561420454162949225855947623565556778316637507581680427926171788227521153474188768527636474851531351464872111922644519558648311605348827873643176413383234342054111120
Row 115088752928243732714826158557543795058674987490641181569380947804336127727671054911224829622483434132023401279436105570576230612824194161714811262641472856925482491856147751051393852266
Row 12350525525656587229693340700132529615742529619881636513269130220571664836191771931573111260421743023476325716137644564369388313071402475415694350427815995300329541253394046972244115004190
Row 13433516411879205518372711216356337311751244135514899144911942505584237114067143943863462287112404201411344103241472711744661276633451484422346508245110764365348257242602723388315340424991971
Row 14500340446193954200457384379440863131743379340634691705683341118704473430214921638550045949642923334755923045367948774650390735011751692455313762924412386352444572863930708470860350611290
Row 1510953447363241234346594921583345249368131555134541113992711742108154883706605143828801252821109349107126575058291717635800409848153748235578619042731874325685545249435246372955189804736
Row 16237531293157324389043875239435143757304074103253795947244750964644942884652397741355645551473847213911487355521075638131476979333020821484519247485137513317175223525836914587583659164324
Row 1740945326753465122574234147225659625646214942622176281488731803728389214495224544151294429954519552825961022260748567043925105310751401017411810282515351942662466519246199448521829252792
Row 185110354135654585174445865993462523674575639263456823002908236052912975410752295689526522571766528410487822132308312634775030231155854071507626611632142110155957432982289040921793515153524800
Row 195675195815101071365449624186912112918332853418442903429131733211909945618339146571541466984453024590341728305462597032173875421447664722474227901533984554792142370141242534974272558664587
Row 2043824315590189202123032495554157046763557104724664574281155298737008362844944519156857811491899231353622562280045813860462359091169255024539101055830398594257721991135321075062458272
Row 2133132521506930872473409660417595062659641562131547745946286340757644017676196952115317423946734237456192403873378435433917282455958242046501348692033245337409433093172475755337615575
Row 2259862972315313542661305143923543635380339912533745402315405590393513352404512314246242335300047735334481122826985023581652801255225431421493303949003433516584927152885274431811567230618525513
Row 2354642408495659043000136359505607323631345741536025322757217725813182277528473140021356556513484970293315125719115666490057875673948210438911386106645023576211851551310502440621267521312205946
Row 2426236891892517656643614290827145900936431740226431349180855061609500537132780222410246185000284327645194443228910591817831506259348345757884556410735609813882335752671172411115914165975
Row 255514167507885721061273787302573236228855324931402329475847118839253863239490380658802408435834363098137559782943300335110795881227479912881728209314652417102393332417857074454473452
Row 26646253146528407393770540443655200995342382126232036562528267242943210523553072987545518465662418053244655220946347841495561657234917654034324348294481211046744997574194373511683221198
Row 2746792487520858972133162434937554155556925344503251521172401154558112668167952152362348115153833401206228241297342658292593353822705523342659115144565118503176845547632495578123722754541991
Row 283995129320761857505528865635131356544216453811173511478618661857449437135422797884517323451173127916524480473928661636328235145535636154180204557531241990331214893875570649213940531231211031
Row 29977395446803218464541234906584025083079287533456553420095275572828685766387114755103488128848212637127234632371348036719351513508704375122582536182212077834351376328547431338189814824483
Row 3014622660474232247515790440122826751766334017415168270245612385644417041862054402376936305819359123763004280572913865863118751823348895288156550684957247426351483121832053776152921515120937
Row 31515359342558190627761992212626728117483606428319534227950252153841682078537413639545470492556683504441741033060275556344352033109133856072239445918624918593548059375755355362120532765557
Row 322819488632845158508048612282196112058285789548847154052525715984460143017934209368945430491344396319465255192753225833341943533292483851447572172690571256072557169225985021384575571458232279
Row 33359652794649187123293951589524162438409846834281210587843394763135753594852531443443715181417361304802180350571372234895147484129134713163962463043641469238728504373409387249005749155957644752
Row 344199452654244377572041443820116511447252240489444542464271066117813605774554308155791209348179213462202436685727241360264221034604761436547612722403045985729307488541443395029527423424995
Row 35118422911773577449531813265740399837774423385535355128543251347773632684259351749854192549525622297457915456604566158156802690288725904003503407110156445784468346212318254213187134862249
Row 3680348511418392020791310382316624966294672415971200435961133664137350932532452226547138822053225516541709386544112502364267131295551116551847828691228190250484666791126650652406056312154
Row 378563707437644335072348314915043263351347281421103369215326372168348602152451353863251498512124600455021611499011646369326373213204090515344485354057245782351031807483159339434334673824
Row 382035236938504193440244719155032718252869129313157134219394573998936309838975880138835311543401227012275897315557762910427752503675406242293315416646815184499718473036457234802517335747174965
Row 3912558193482542184217190419072872195535492071306244149183041662747427509937484074450825032867525110223658735400262238131111571020911041368120693590932364235644967208719704634252215305449
Row 4028781393470243075553557366431835363191127225635274194109232252056278715524793302347810519914392373347831305292160228945467532329422966541551216313670572528335961787499922211261369741494691
Row 41546217857794837313710422549411752013022425757924973775396831533979249050932314302534052229641557442672200296659074562268710943756307143782091543745415433290152973692390348563102231214435431866
Row 42103337505290404119593601493911051441333838526003858588215504904788370331143871119746255452951587740150115002718456138625373240633175497516116273662298344845210227018046163868293113176421294
Row 4344903040127328152467117043776485791287457920871492582846261586544249253663129221784302151715802986541311259659855933214058314750420473200623792494371328541255176016725704095208115031024647
Row 44244953725613326234822184590521765160451579650905253395522937211643621494115184895738410814982491118740641033185016747251983260915392477477410133543904288058224549842250428228439844054778
Row 45321998074463612566146913044123495478682619830788642101100856711462142741522032634123366132711703682194912442592461887958445909541868327005793483351523781283520810064753535738193264
Row 461045555844044573361466554555432340957564100168656335110146749551562997408546715144188780520142233244385856783824883828486337172824331023328909037962947900313331722355146319173617863960
Row 4759804229221428745701788469294643381623493543463906211119331658102541937874265123229674311667129138223582288422153981421216185501403250952662564459124315627380360915053800410158201641802
Row 482248277777540002027525255551932293837333082273278379852936065047509858311309343117224064455130931763160351759093361885257355001160560560326028295327136018644904312731191199346243321734090
Row 49475215901891303552853612738376415712714323056132845194052587650613144325460131318526354404151984157054184755505821328964410948425732661686127332965274244115715644492642141501322413875

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.