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 0209049878631415688255610782666271762831533329543755835666418539139932967230317102808143914175857442405654049725093514010624079224764766255835541432527441814585260336184167226918024558261
Row 1476986019711577229933881433274014441973171253611122773461411145249338036712802481129459823396554746001562181640112020765170979404774632781434217917287741511729341252634501202537637505405
Row 24047551421599115321611538132317223535323291442957024270247544815473908262615647847773293419640179322041655435625446293384054521625545059901756262123422288591277019894182324424375729
Row 311525063129219365839458413158793773512945919597547561238144208163632634197339158845395679579513081668397745524104370557033166499716393005358017692883395721193177387620931932388859071405523
Row 431694336291430524874259228471824260823473423634527443755283523752532110318435415506039622591293654452382359604662346312929983260180187258513027205441103849787473237652236000589952982532
Row 510011140194661510145372996515530603819511517224164224447191423242359112745450264453843298343058575674265358565572195023885733090433363321912870362913465929144846016505612270336810345126958
Row 62308457636021692187310311548154736841404111856333791169127222124232349134993595225849211399718570101034209382044254618964352112154974429945281591454042112995565838447851349565290836715478
Row 719003623573582150224521391323872232920764174224427153837214704531424920613071245950552729302583940778672747174834446475371795468439253085844244401318649948181410925355513113954886
Row 833793455195758382509468614023482762100750954510135037413880142932082272195840666953591252119351762661211855301791351344165170967372500734765057514658241819152491832815022659420829315867480
Row 948883933117552465184236844211844448539513635199723662805296427381811439179495726336131109518039412611183921485541170626284429563838023675482116920966654654464299650241211043614514929154053
Row 1094338714315455549803495249615915333464311321038127055606755071323454965240532916038935375445945431786556221569352476209187834745234335326201829289171351157120482389284016073064191148412559
Row 11115141692718504335441176358653307385741264321359502142356044722574288648955013802183910725849422839111456129158222963849973446556615200817423600133824803341160156923290374232521762316137
Row 1222515817393840908883787231747995242360746215538145555934002202156081037633208134724254829485934383869031855600100533211850821125859401708504522565074286586351273823131747191825333843261835
Row 1311001533318213422081129127559198194459551918231779136926443037130843522081356448583673426398441894743270314208110291848318025615029452146425158579645615976425440791798335447444230707542793
Row 14515043181651551717435635370548523373718256533665566574559264594426645683751406131283726231512075524234765339655417140775845665724240940831467204317871952438055054517174550704261167136642527239
Row 151415588336751402903457346645250522626294666632338632323565795131418221837310137732172605228919621675550363253393077387175336641237589356758094557581650341185448156664571171222436530261843
Row 1620212656164182731190423794405245411374455303881449731945118438937604926294535753960412920563626270037673647106479354891265918510416833648100840622053346240735796299119534292185107026813944
Row 1759965626151939563755357415814541341522715172133471627823050382044656984828252627502289598254552792551837546436213518340736173143492615728972499315313503839237928675972109556483021491541123719
Row 1837426384683012353013530937863849477214061366217950224509110459454053603374675414421253621141312193269443413313802152387520182619390432525632321310383480198524434846416314653355526720592759
Row 192869580435134310592811335722114744014156128057813075154179829263058505025572708737225425304883417399522375683534995255258572508861578436405839312041473822111821504513643619197044222669
Row 2045274692275645639465286344613633280568310453333467735963189118544572973482550393903865377711326862821147730547915899297333184590572918815536501453268982294500819435626368555392814486939955787
Row 21369430343689455881038021244363152791548242251774521573937674249161933023263945420055565952142518236375680199625063674178219970754704757151732726000514725501548156817266913075492431829252794
Row 22158038709931136382111343171458814231339644487409441625194356429197118352919585833844467142651104535273246022852565713954432352623885568134735215885280443342197767282129049292015385318472726
Row 23468847662583207232324008118117667395782461839611773050392135642617526710852502207154194698283722394987176642542840361397915272378356235995609156947791375230845615993270457383042624330156595890
Row 24438621601961380485847974358445634296268441755275421155228371809161440658715367145148152834174885457040402186422939305713895890437412464687441610905250271237733424198719833976482337924137
Row 2532284379567239423526120013582411576953974596399833275167438632173540563219031956721115246684494457665447725515477426868827052646359646172155820032582132714001178532547263443710194238833342
Row 2638455839406249974506255535725159303112346361299810134039441169198541152727398869640535387187433774112221710875410044283899593824902895444350454673602207658922373374139935761317256855615432
Row 275294354812833462934200172310464217181011004316238499842542727189226961771235929838462948253512204346110253691356711967206321920943552152409542751198231185229762732212954880304931861576
Row 2848205545187426662492440838858384518420175041882387195614064481550815582575378327554886386750525512418934643921237353259675730761840272255672486064044765102621542952341241104358189336185915
Row 294468140026703353526717212865345620671256469255981223474826743063147022413310207526442074310147985025512290833832405525329787219255967422411911688108846463754234433383352356620862562835552266
Row 30393856304909112730370750363242614241856471139571551830635681474242541368582928995122217323724735738232324983665878476343035507367243142237137933505479199357675125313154825642193516243834446
Row 3153042121345565238415812125122390446234883781338547903288105731045524243645350024428220412615585701376817504863215119653933621540504474631211168868102457901355480431751452091423232481615
Row 32667370161650943920474265236202509240224824659259718745021413791857671258208563422811875198810855050213331763281538047903948308054063042999414836934619657941101531626912975433682838924103
Row 33208559774736436618527245450901285626264181223614162128531582251693144969286249335625295633494056473008327647489913782558876114923272783737336273693299818085928441339355243523431045557
Row 344203596544893828292145222768256715304330402428142155983304153552030237289336576438915464599223033399523415375024791574046732803567338718013345953333137729935758179825903062333231103091
Row 3557034002748576718922115758419536094991573241113781547145781061303719642862337119171923747491059495544149930112875460910225782611849234445021059210226974668109324292778487318991355593449363319
Row 362795230752362986534145293555975644594524714253465049863894139353651952349420616194586448933973459388475133925324207018616301305317116835450105127950934937503345942798420898841913572
Row 37294016845632355826941219553727450957051119383317751304546330794475114525294579242416224628173496647222971317457091161745264828443772063113449711608403006865195883926393262301571817361446
Row 38224631538693867494340422833366410126337321737512150171127227212956241387296926292251492734684890218837684608392452138544239308247213181112315538452135155942174308230942383324343544645453
Row 3930595850242156872101134731549913535922559914581354525696321751722877434072537214742284193847814592176210520274639155750854489397747725905324192615812858284811794316298216314012198803888
Row 40453815274609501138115473792240372258974429536014533514384954302286443947534211191611105811985926404028283937423836314825277551583434178629683980557853704701547437994061926131219093563597347
Row 415108180836671828661563644906439145815143202134051918117883837044145481732813514351827541312157836802624348640352213833314320294199386148945761450457994152308549421724898601349132745635494
Row 42144184330083661459743205238227794327243111164557345431924755131420854516581818842667290282628383391168641874718248368148612091688252268750071760296359504484327411135040727430437952041389
Row 4323101859227349774760309918142151478418685032368157291122436822511809337540104772332424942045443715342772274053284813312916386715402614543125002428158212832428244931510921781436447644283245
Row 4418512438201651744932406136104658333505792564534791430316288020435747537944701328662898377697610065954241254824382565613328201671506575157324116215564446672091944143652448243478270
Row 45420219481598486428465373584038525327225133343708190746664528357851714278330932874492387317524499408136965934460525193412487572153594725584220558455423575172167433902879358120551407115812265684
Row 464467451241762339264267442039592608502547719390011985378437178115824216204163833871878502726654581082167261623071356508281955321420108222051840504148138645517483147637154208313414955790
Row 4713501699142747373577454500330351536674365038422030273146601561415157423766599047822578854429914095617501356162751508540541012207832283757831286183928172821251346766345433197532310313485064
Row 4838691338384544721912144185518081156147145591664876265938701707549536532993133346958143846935476238841325798249154794862359817270780630074850266148156413133731669500631553971355263191
Row 49370685936603519470445953994109127273792358122052654394030215360474528421014064843421655362216588545422246542352551772261429602630273478133348684471242315942263437994916394381942762688847

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.