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 037298731244551557549054783301413141355904978202237602166223645385147359011322833912219476342983562472819655123425437116665660365822243660569724903662184310884226474726294855495355241570180
Row 1525938654945281542956514365268463256361745310632531933540179612343484912297959210711805534330122559856304666448929351222402302949425806450354565261371644001573397846142786230831884841
Row 242711836549857101725802245735983233346257934065101161355265455399333884390185852352380443990815860519791130549531809814333480427118514249457712491136262834654684682453212461667154828804127
Row 3215162554042574473139157764341444715392377293317931161276121165501556016663858378422403813265753835209469440453356600181552047401553455663922391956872059895870505929699635025541131224888
Row 412634231576025543243906633384352349932373508822272587371722423241204558483845460750112459315320563166648238243375011531316054370394959934091732253748024077555529724410915155489307220883064
Row 53026526144171790370829533362419512222095404542245645233447349804528564849523067579618410111973326920745369327124472013308341043425431247862382362995241061781278729693179238043071420592829964926
Row 6182329324973527489917065651504119234939473995670293720284081371541858321439537725601024112380343772360382059041317597537053808132248122106325671922284828665124183848744131581248727002684
Row 741363589432336072876459424541044161658682147302358530749526672145531219141258114253421622272424032474487622351288444952953619313219863296273341930431924091116232293525363716113163383337103060
Row 840131379592416103557245628942830384711799053251530312762494913104131416619954253131420105814234031668164003343843431077214847596302003221553355784540724321928354971215846525138103430161267
Row 933802549233843162803780485403428811836297255503898366655621128210113112414500933805798263050434874553417612282113220124864841169533502931693622294293438987052252464121661316401534404321764
Row 1049185317382721585023189154792643106172729881399594038444871781504728924479463939751683481215515703955290056967128522135579054834178280311241649032944491438512797395823462222387329225564259
Row 113527381750237235820225172590927814901568657045122372527743550150520464012317258212520108045580946624770509755473176424358144211691163292818511321051761547518713933252322704572555131211642
Row 12429831762677433148057482042501941592082207964917952011532156974262558637953494432313741251928321024901656201318284012417030334595372140642007106015842554276648845949554620542846527420451897243
Row 13203395933954915897307418042652240626071585187118414548479130683421414871115246144275258235554124477640991519825447401855949391629594954530652268411456442521551221445032635280934275801878
Row 144338666418322982164422440651402111348007067261502137021205158488298941151259309816682504339284714724106933076233956402789476433342361286216831781632385127533823829278627804725119245351020
Row 155274438713203958123091017466816821336394819813943773456120213919553850705728594536563853117033752875484425793153129391223797921102822237173739481875124154552041862356345060044755493253
Row 16569948953350466827644108486415115139205615003119290031123817592994405543248581270209017975593307410227972470533042544088245409242859634033163653719313942301922704873405440151664331211601121
Row 17904244911217905332149955393791255742232330330616672697396321153600351330034890219237365509100219543605325937569453890826281473416814963576467249757703420358115494369565232753447686872685
Row 1894825142493222140034298537294639863052551025761004312038225003469016645693559944703236808083473138351222445403837719505219290548933055313511210621019422329564035143315672445609595637614500
Row 195507235058994673386958145056189420141076524043071426310311324837141637109231313522300200517559046714015255866144178354133991383057406745288515421915364106412932084124937122281248638785750
Row 2046995746769137616432262139637792926109030241144309255391538102651635987348748654706683468576046623619314617972396354949553470395712847705919280737906093723314512736345144366019026327743782
Row 211352525355740563588443731101479270331502568364411662987367161731445078414520121653163456981883122344013519011857124715494325271578013724404192431211941336353437092463257651525660100336423314
Row 221022158735682893373275830064564452861318173771480027215310335927755190557412843602476116111974483145132733782308224341567589238953905106037812633954806421220314657494510833944987351138841692
Row 232952924222955614289406943571296172729132670575923891423354427283984531485936189863316792461212829262449446613923092183382497037231963407010833383103613432537314292645203161529530213583366
Row 2445241172645485754893158299211540642204891482879826232554106847472481367835128014991153213540422340578829524153216421184104595238333344542730883043566833471467399526103943121441048037785524
Row 25401550496545592740524292052146502684397045066443343910154543413545723471846091441537252147535152948404949191129485053565857591408221522161783259368516481225463260056562467302424931524
Row 2615505070118827783661565326937014145500494348901803459395750554113053215227481806458329005747555721611812446904999274759922492514530334731553398533438461032101762510238314471178718094832
Row 27358447875808196035605032440354801652166565247926565201278445216859161455294436175060364350613442176351773737875749117867432654231062745573216046744263124039825412205145307623627383110
Row 28577253344021135552355275632574156354154582624435634818318263149575662508218432061509078114351802152539433976208239114696537156675166493935715420427019909605809464322824594221386135392475782
Row 291928290552084050249556343523742553514873416598034041409182946144127169616743848441831073339527743176357183345473857335030588224401475323529152045449810895524274437772976405146611695165041484739
Row 309914454582459857455624336354513675541413974476420853435916308547329992739311925611796574524001357463633855469250034435892349936093425213300200810692142143123448654520585512813887398037963821
Row 31198420883817103773751303115535257513267072896154625231013278340835942132585652062521261960739671581543354441653208717456815834103118523131635005420534931512254442358856561822269631613865
Row 321697511185533715204289627594228233163311224798241242791448555308622384593901547384239184342111838293309102918013763511728564184422165239151350287121810453043933224993420212658102237815148
Row 331503392916215227833172489024863743402428525477577318931582601482347911233728980374438937626981693393134036504415244451479248093226737398113451410697293959831775423118443584506731694335
Row 3498855174067263425787002448242574521971112027587852304872153051662719441946275581131440427681487517052274905297221350514284575752925931520740388017825336562748024377116242153790583155685250
Row 35565525743531168994224143693058142552653793440179753939784826286946536673427375148422031152625430404761220548352393146591150846413181584531477023463889342741745843520931093278194445264120
Row 363554115426461478103442295619691268151913942035139354136731823843431226621269216041081222972208529482606298326055582185029412464291226374924324069501811098354732824100346518739044694760
Row 3730723754166641553507318164017428401549448720221595153389241834260556577740628083074339629584730578424105646180527322863830236118832144125129912255120176847743511478440535503502134355733286
Row 382985128437313625203408342727843005921254122034556369242991078209643972464303937048657624098579043833045396620343832251419943834299432210301671101155857762168410718490525432060118256541922
Row 39358337416442505203819652835741400718535775560017382795136079846455424455022239774884165017354127317353602297248233594476175352963195410718242934811419229050142305276926604951052523818794615
Row 40961129211195668515413966381253614645101621932073467231846783021319023545296140788416332385380050814854145323201668168747442355207772925115286397943893080479349211798681086920495748451179
Row 4132031352170123365378456171612155713743372246748792535534596765274657754456190627093281573620492684218038682261331126043310287234923072208482512222332132769298610702204258995119394044856
Row 423038439914712585567642123239226824852897138751975875362535867474355564758142220084142538610522143228946447364907480265743159373035190139391540587158005168821188583932061455042140715302080
Row 4338898551307308257704007250512863430517630707382075484573011493969537243235505723342844431533342941541452034423815051121319209246623255564452871712465912843221309467220552499411044185663395
Row 443576304930852941372444634884458427562959341048409271335169850022428539625763062176149432988256635944574536365194054385053584041361909408653653331380722223318332957051638481523231704402850273602
Row 453985701559419063122426922365646565450833274869137523141446042382469633221103357122516248273498116546622722412613886434761192348331272488837671960266819175054033893543799138636423484595
Row 464104521112651675542251474033371556122226163484361338875141448031269342923212232651751377133441640537455053038487614334704780550559442985549826197422287452129991102151944273034506854292714952
Row 471700233611645766867166541238239355384765217727132876140758624244452112982574142351439974826491256934640444943372806447714152777321034692692401821841203288384357864375343747084146492539673829
Row 4811612818186259335521159030231907238245085154432536304606436242442251432667418507712177828201933415170905886958502465380503489199638855317346353957883380424854532613506843561347073385
Row 49245256475147491917965231389014455407381163416361223576825413447801473219512278102849691095594177555236252815774502952835015106328312696164954961155142473850347064345314559531147251259632465

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.