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 0599857431856484069040402090568023352131541347971303380980265121712040303237362533114717091769288232111222464327265251114342091332506942352450542798416354663567313927265435663356247891286
Row 1511955285448249323511464444162229701552437278736213396531147131426456553112755318292649435588165132864038255840094226246469815433485328586228834774486820151142109317735745138598656866655764
Row 239372272330927035826268948272942205841022942342945683996246379254042222330345221868494015945879840433518453248895392290169112265977131014472772251311944514993873359340455938118455758685605
Row 336013606166076411094490520954431128395359482122433458331729707245539415691127548819014037125723334751170756741394299613216763342497747665798569046463410319121804010549929283368142816543182045
Row 44733231412202928273536451957254739775557552815582669322894446136965455458146816241305230947562409505490830591264123347715563386428865632539405913655642853133151853883228454121280197854861491
Row 547375967121826304490337349394944802942276347584145724731433519934371455923107938432697238727345045451462627564659862077578444772810650931388503512359405332468338825604049383853204110
Row 61144547840545110552264637234958479171954440753439274767138828387444333928148435624798390948324854504028853324226980200556725197494139281687539968823968440418019353364814337443743515
Row 7111739524346535935375990834295479148743488252247483134747151459278273435131514785081643154954803185354038502354369838513351112723812311080440414175378116229684994554210766341910443446743480
Row 83237516219565659544159515306263555610096505519143022513958462241455421110633288724222815471822395904534529462487331346768181461273065731631085178127033365369834255383829450921528751996
Row 9491026251882198553733324113723166357254233432138843912149931871836682396610311503226244101774445944711009470640792922372744545272390451784061563913623626255422223223445373721133952310
Row 10924295612185651220048082445237517803798160151644238346621958515283101734202667287121682066189537505574442478050304483201923052017348641132637437657632359950357581637425898137436355156784218
Row 114449368334759865367253854562343526326661450546947269015089437651975293300259630973089176420863335372059531475197250428255885994993944551032975998482045418313549230051654292258920291711774
Row 1232935090125955774971327030236073769435858131941275240154172027129112361859189620014706587517699525596526638432850315912572075143317194291519057463152820550942054176376695218072825444137922321
Row 1349652968467129032851116427381229190722321169374219693119021427885542198748125514331230442531913348536481770284034663855135013315670265819632485350049793673573539883561134024421803135727632623
Row 143953127274852473834205534571261240844852930132930313215175133442084717747135455772433222879921924603587210555553983264959495043870581158313738496897112942212494103553643874565238678314141
Row 15312425482930361717831368274734061763446824632961824576359232564397521394134234193053205361795349617125982238735464509260493915052061190290539336436743392876610131758235049209421454713745
Row 16229434012927721243182914078623612830460820412802579717224283083202402225872418169815125156493232294276170534555593284299921402554297933163931446341595587508144711141292587946807435716611
Row 17320859673815905313611947372262163228454715759115926612892500349853375400986650821618267381715351794482188222892422322332962985497126911565164353611792330174236952828133939771093614831050
Row 18364412762230256730482928736727277440244565560314225366119443065254231847622500580362445313569415464916341732550817196405079196854775581394237641890493245104374386046493653921291578656983844
Row 1925264965414451419624847169317485047434687226453638277413175781255215752423179048261812543624642312530386747141622557273824363872534156185889210617944041340532312716223724162142190044102482
Row 20255075457742783573133226312891517137463294170138282028503187824394434953564258054241302102111152794433550519744487538626564574238337401152182917938523059727248256130983838615486310133554
Row 2114145027431322226914597286714581685129534344256399010433287125535101538424717557394750520014812195339459122786277926473944534690231257611205319471632682224254428524427250257675091265319003813
Row 22469527213283127572325356484592157057961882266745409542625503126020602654938711392244524470506043402635037233453887515862737197242832535525510561939289853765642186106914654511502349765320
Row 234252874665154733152111135384826942400566405330241047541455094817134528934587283758272835476717873455469231455323441275223469678744625325572938933247453742331662241520661871509826809785489
Row 24422624424329167254854832623039367079030494480368137284252395352729393241229228091014480412622985736276218071191507173620691141352149152311198056031970154917202564595848955448472156233495
Row 251766171747382801499488198728903420325648536271863292649154087321490526316755458167555773804286822814935504539615573483685409510350542973411818243253410174833412527734234863525531722748
Row 2612514546457123024592213927522945287225250407361746450926469275383528253501557110303016592824023587260724651614471132256762674579350810263642854381939061748531824815265381228238238054753
Row 274123142449016282872281724094475402738133984285038944379370349913135561701361557912785200571611314966904250321462739261391450327181434446233423034575460124929063920230124447978437453466
Row 2855263444762997267842391892212141724865373242584045376724734437593557734384333486130971435446127715156445832612437840589656065984456183052225693123554924748445711303412102718002344192346692058
Row 29437855743452404154353851501466215132693326354632162137353729114921433948151205114534704260425251051832212238822033434207940131111592148139562485846125603240927592627094553117450472051
Row 30512333923869184613249312461243195816014055390328782081357126004285288848973016236948941073804322283647722789190412302404391033275163377552603123463491351673458159121327772735171530740201007
Row 3161756551087355220083350565721732095590531362474876125856504874556559661855248845801208411835558353188287754447704679468028915644190046659773462521858312932415654663765226153329523771295124
Row 325053382239922763152513265945546252655575262120049795248122494829498030224386354550184560226130052491377825645115160951461674319224613077447632643008514849581992066423470013211574514
Row 332764752192929430734467218648738968267653425535264829723626168543724491299549136842442336468058115113851290497200833265739558138171434555874731381953482811982695584935141144561861308
Row 3459765213103047113103047268650293727533528493811378159023661623535531632583055258271246231199208437391595209958203738151254165439109856594085258984421163960322736744952238511523812471823625935
Row 3539346531890301119762126530346341818114627624022396650586346817824613407846534418590522216293940684349780508547562680277242013921438843122612297026200634521887422126834176546643892164250
Row 367539647423627812804763009312236916671491543637641716371137374454789288174251745553834501997537156725121231074116131168135138205862573336213869330713622804586640205492275021011262163
Row 3767947344818460645052621401786643872591139147512905994560631344194387510213384599150431659570643183371853335716172731844694157637092319321725344269527144074860490548553464024244419128165283
Row 384692412148252101147880510105466658288938721952287350225088306964155202942743908579359634811348059294864562536158887994400327283636582098386289143382787531023425514420861507113348003232
Row 39270551015152102172484540148219733532515182342514301378545024968195439775597571661416739982800357957715881300715183654181538122165841818573984647883596146027862145595114874905237628864497
Row 408365130309283070932052258464825423619876128454714135553713632907587820852410296525553441496480250475992194453483116923492226595522210913123199347734225697452221274455389140243096487839581708
Row 415642290233923035206550735521655269929815844426336722534965189856841290537027044499271221724614866418753819583282578650259705437252817474383452753704132491520623058582957137744470944225394
Row 422484270431135923277245533305472421161535192413824087588511515978834893844358513584942674270525843392822075300316850674561028299813231975591033564976247037723434987186219481755583213814978
Row 4341563996246529862105514718874954264715562982132520139533382171744307343472351360354485363290555773700369510524553549922025281395338734603202550117089264113408125002683363245413004358406744
Row 44507129212313241191021405946599552233224332758992782256956752295250580241011359156323711596119559010352664408245275088367044182059319449655264249424861990246372267436225944649257355502899236
Row 454766412231685048470851214361456655403963177224052018540445553567945592829152000100845693634032541562470212592693284313042940204913444046391503438750517524793623346158734695368714962564651
Row 465316447539559702307263225431578388336992722389729291371922277846106854862038051271290479064317624502154436741641373413883820585413001165158814654590277513781788547444075785213823745888936
Row 471442227150421955314310243225211527075384595041045094474143959051535594653054970566759682383275922221276369645761156344221178023824271741423165255112040945535786314942562867822366385233731352
Row 48320824982224278829262707616917254635936234199158960008404313558425722943226532641530443255942163391621561960358514731362246312554272368754525152638580318882754545220815505499173036263294
Row 492760538957245300865114128357522377430226501689357130072995497163164441933605310624524084328565516394298815378429891464598429874901362648250055613505359104748378454201931706521382055292484

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.