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 046092101710349140971218415514088497387949612691445317562262336945204157484508204426554618162116823469232643295553535210865842314646243331851325549915270278638683196357638513435535620463259
Row 140102819410748391848120449425567931294642533211694309049112555829841881183911112466229254754195185157223612971533416425224462512648472587005434882181212012732231882008149642354685891
Row 236644463389412243393211353607433457319657075522404784154521592474611951830157427454653439429828423034365337426664058568320854154283520495033595703481651967142511158210959955791134221653544
Row 33770374324633703141496237581435524109127064735323110015204556527427413869102139515231126925505544248582414531620343764738344923125193759759089856145343562827933624231816033087357732282909
Row 440163727155529854587276235134951504135692780384592518123005288115693462146430337594297539504161229950594992270527188532875468340055432926569648874862323639271160329122827545959188539992052
Row 5278415432533039578047714335203013902865775392158383842841043057226857404252406027162935183357775757272245222576226457682422190457664903846438515092825560334514997298758115224510738751264273
Row 6566848576481257380309547791372324923921566553256761566380041043415771296567759003119976123112236704419549630791078479629111916579921369854768471733724579773521181840445598387187849554057
Row 72843363062914353425383220417601994442255582840293453743009224518101191572441305114617377821320158378550125967178122226396665955332637553830340624664275249849975375457241894889375832602384
Row 8373340352846409556667365662563539159317481234305435028951899410149855588988556623224907154217384679503444814365880460817151634177223924913134102455924553540126425370586453875929329325113829
Row 955301475214332294631332497197928684124413329527763136283756821175136276615163069336652085003441848331594174520661274197748573570820884464577338065302398636811253927252529492582580741113555
Row 104514209148053400516219902123519838811385152675140134183144256692308164840415158333430385849406953942899224924301648260095614774642285134831747355712051666770587337861291995633172041863509228
Row 11542272813271395251218575531680303658522545413218622714275280137828113121454945061331106126642083128637802882486213511108477881130611355350442152319217894517384159044340925449155726215509
Row 1258515509443014077211068277829553287453819821213483052658274790358243653454819638441363542328065470480420932815633058577034652284204741754162718261044613244161342652419143378428201513893
Row 136833445261288053924244870189943405884713421727262497338541649341076175243033063461669257319375138353861579944125361118359321814487118028447442488519460124275472310327581376441526892227
Row 142047485914772621380454679343859122428138376021063241597729731064215836854057407338181641110154125756177058611708328713322580400054795371294036194624475712111196596942313090347913754398399
Row 153047418466837152630128938254592137849231008223845623706437116733407583717013340522220801791340923126915778621305844328741865631276540781327059064560125054226724850385324531092539420411326
Row 1636713014644650532949215747637155647134145152335973664421425585878304258494824309417024064217227964411149142802243329711461316202752913507417518971793892199117075171343756042598111125172934
Row 171694250853184499291665717836754929488135992314380957594257692290395617651969157340282321435635648903053562529538005201154490596046685850478540454523585127253112241227349555649432565888
Row 184820598228964813307559741237355020363711317825585896250126341044435528354097235037856622163265136905441194659853938517151273727545229286223540052265121325575369278250252074424754186649672080
Row 19832534557495687889162382626905373260946474148311139003166452867954245496179417754380103826004949372616802251644405917172824636326237575584462611904258429984509958107871361557194091
Row 2053714840265410815840433522745035790457311715123367843205839271924533083571260630752248244943871498404950234648475444159332031426270541204874222350330111759451913254047289253423028391845994969
Row 21181524393386421943185256581934772708266631117493613278747031115943593432320872665356245323122782306554832430328374318701948585544384822205435717874738128929225093192512242871500395359101545
Row 22798573618562190551420424100369929253972324220014890250543237811161682693274350231976412926646322059143918053771492341461189235874151366325719602062194215515823316041825448347443582901839
Row 23230456715716514951343665584417964797560713074116313826971272586332961005353939235644170859755727152135834560112430154877510355121934661502445491758570941994755756152043534604606507512947993317
Row 24394512485521437413439652769689517123209254364340918434858161410071677337539393591390733063602367150795724297049303212281453471048245529012927365731085625113832772894446366312435070155745475281
Row 2557042097404235421357230826336193638617560113733888513730911763158627795197479216261897443180853351856853723175820764617979544273450729624962478650094300297844955825481855902743215815072294
Row 26261679625741315272057415489277023493128214651115170412490343721642350824554286180285320625690351759053774454853245299376107757955281236324365533583459491292415529825608232019538361480635344
Row 2733247124982103404167470019611409387251595341395136016901664519131632012551812522983278134069104313145232935114231289554759793280470089455714713522747981987474966259703468803339029911584
Row 28462025824197109752193931516358322904151120033770306384752023372346590429294622492957333254236825815678535320964685447441205197363548765292564433082165188911215764387162532385147348632863409881
Row 291067322646594100342435714784426617104962301033254404715827121391689211891542319433332745363813133012227397138313702451382734122697472912774707282834601047564631414808397715355604443022361208
Row 301748513679714773653372411151574409489548324366236651843694528623271286504418685919417123523769382611956613681795406174951291075268044069144080381011494562412624841378140249362200391340124829
Row 31494951026937447765204391957658681805393147275342369493020622021281458822356416124995948927596139463649179348393995546025231698230046223663103442108108671167323443612832692495347121159
Row 3212054059261715344362288950851741493522594983390456530223029524033883975439553022192540631193973176671970634792917996534836175697137315838762584200053884860912448246274882190487289044912309
Row 33159225801566161542362530219628413757493415685894100217486427633949586548681528222425054765897262816913932138374313752222904130243694306382621071595148329524440809110422024087348337613176900
Row 344998257554623524266053373333459829908501187470616401123372228041513477163540197244841515189836902430324342262224243534055494189247772452476350005891996153766390759082361022586331323917608
Row 353374391121631253268439851635160418862688242124276137412441014278537362474419349533502571281604453929815064230791192049421653164922181823392927056724667516327795882278711552841493052541569
Row 3628285660287015461357693553018357001663158335093713204721465496284247395302510738126522828672985328756674708616452164461046325126479140381555285239922594345575318247456491752305536112605
Row 373946354449685409305254323533439846551952500412542721676358122721514555182442290026493097307347844556411124433068215348051497571343803751667225826213443136240765452448318019462388281151924439
Row 38252426541495597993148143110160233815216283440105660107018940682112582299380340285096495154471214503953151265186490027354743643487955702149153944782999477855861444208042632935920283136983353
Row 39928303348999924405314715153622252679052545172513287658765785368913002701472027175939276113033982052837474145401794468353157252241405618771207294432678032666334852428616712566582935344454
Row 409042497488627482605177184615116547523602151941425943230110785202197403347978063585303325023341526645922061265548572533093785567453694221384336532811191545258441637172927812236255927173389
Row 4177224782437217212092405511630364430162338092711101059602267212544205500420920746202877452980140831046785897101646407515132835950967170723631778523930604481215638452520973531171858302753
Row 422553196112851709418433441786520544602945334871132256753442312082138569551721569327237321427523214589679544298266328125102584421283971480282327131696423111343411485519472400478647225222603
Row 431275155055383662258741771624509564864514915050249251073921568014295060233722633093474544329202782265302733872969457817478778804561374759843395201246932451178238064880349850474516111729805271
Row 4421416324174410949571131137349634297209554421306123824424676343911667181485511443945796161146702423254386784455211188242459815616496223935012580219735844372112575067416530424635221732384675
Row 455752245532971658591167612404340180045211589516754723616504930773824109494632871958370515805752382231443362130498544202730287249164973572345905462001563257639453360137312344812243351495131204
Row 46275645981193997763326930863663140274321202579345312662323133159093637465257954605647284413051945256942689387134476119067158382852974455375366611155539298557211477133426285231337011312001
Row 47870515867786957364266441132839082529885490836934583422077461432923908566550681057372040704436925594842764365605370320981693246754583836500834265823741212171978818874111511129253131066
Row 485056465446235641260017822153342839939026581556591634132515484740328247322298152729905241261051185933371179016855238421151321479447404258545701242255384676165545525412458720905152113251953365
Row 4951482206154420002362134524252924114755215923255812125857296855811608241618974707268897448253835226240463146328915151726280322132102458114832001248217603032022133757129019944295401781859095190

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.