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 0531931543195704910349855122063902521887277554633000589236662278905808503756154752399927651686232134395753176339165843108210691621652597836591163184156012142070433567750694226434213465131
Row 151493834745390043811509558670149485338246428635180354539325342519639103000359409345601572163289522495231112159057725157399594995363953395043225405451256225032314174248245108352444155
Row 2408356022248264311732410553734221640658401122179083750317559021389251440646132553585711755056217029175104241539994347569208239482816472551215226426225428664919552308258264302256572856902770
Row 31334303532359905477437821592393348145733921827514224745775195811984895118354591436204843771988512942022895385393059792154406342821477405237585854211151333547835435162392530164936588242133831
Row 41065367152663113204712532241249154116264179152037802241580152562933559511050337102445528642521607321112675433092547943734157314936381269519648913510544543251363624195129155865175221711575310
Row 512816603019372559451270533231552536587424720154247440451641885567243597753182380412062317142731565231129149081402144842182682210712364072052250657385207504256125454105738593858220574335294579
Row 6517711238217223027380948782258510037853659548200234126553238747470657444853913478697336758423955122461369747534639421354631021593524894829481347463929259824054476460027451130183834925836
Row 71581397737483664073111520820272338268572410904907393755259273871304147552684178726835281419111593880936228857174428212312982404587016644769841871250233222138222644111045162496397140322004
Row 857267163790240959961980356738762916585435931343197648903746184655442212830242472315145622948456256063110352457611425527301185733172709185352962755729221212933213554210422111300394927645521
Row 9778518824392937503191549033553003014393114422540423232985856941515051521216487813641344219949173447440921713961173573721743615980310241103170259114643470560453954912214436262209200045671359
Row 1011525782237251611252435143245728441649596820171385214123771364524348645341834195020041438134591535824970312355823536448273333184718324844421152468030141995329298140121713512238830764365874
Row 1116091982824361316354168452752163138165047976731315530399048482778243259991458544619941786242763499154839357459121267218311040905795174422584321960539559715757681015287405849482065490
Row 1249473523593594153082361946280639091339338038212606556239306965357567429533678634234836483912415374856774722696174296116425264896258345723256352913781165486847574985147343192914216936762588
Row 1351221353322114695000361238842747328943565443503053171085429321236672865346811964242463263299936161536131753037054993311828263453394295534439502178209112385341533267585026174560622841424
Row 143529147956652160154226635776307739803067812972342336073317376119012660171040794751294846122843214446129001773452231843197205146622861421120455243986328035044292406147617141668379254753568452
Row 1511851646520341322585486134647182385311932405569315529042303176350044332699148617132035778577467914921441447096650094922215165541242829123609162756305994474528695562506021593792223556582225
Row 164933114439375136922371158142413515242843378416132055528481513285810572749371437535649301822224449252414382228314754040450740851842444554310515553572517530636405895346684454232281217252332007
Row 17110966913633885135864529911968812156585318197351921761151552971916872181412214511170946875355113296815263642974263410334337267218831922120119743890201235393898132955113090309010262386
Row 18500518974200226407590849135761103958801287140328543921243511905924318311217922911002380438294900513333391989222243654375122726125741453667248136542835202451714492230985634135742872265674
Row 19139920185965240058213793129949531132328811755497166224025757423538544247164219851423544632565315715602199451358472424418712454442415136454263194449433216307622304391257238927922328212646452751
Row 2028422863360210771326166423328852364274627324788932397632305082162014921026563470741012793309867368438893000281025345751565153973353728722351849603606588217053384669263743131898171959333390
Row 212744496209784532885194151739723082451778156164268432501216201159573351371193339501918243676368744601989558517919212975292224175071376757044264528336761346379944569612066488859723685475705
Row 22282216530441840198872055274482708511262646292086354810451156131474954205964424766439528801726461176716984146181414039681978444628073966516623344414187314455040502353125871547468739012295
Row 2341064497719487228913598598335253652295149711783698246531562144527211221309160555363182305045753683580116252305266506215243372355822432243448584128403800520551355297383283317613539497610324661
Row 2428426364196346656862771114926539323785531299319022902550414451459983984198547973189112040943572395258541110292788657713211352239666773207737182534714668220330021660410459042210224850483208
Row 2523210332005342121529899210459522102303083718722414358583891715645742741503552424944203690130471940311152959883185526202023222946417224203938427523713913053207191115451565174924623128
Row 26232252032163156341464199246411931385575487112558931331452214295913164634896559110049358964211284524405775459349022903915410450652478224932634942344134014516392845264408394116706228992986
Row 2752561795257625927303471446955745911424441674812114650822916210156051643473501260587450175335399342544731068404753714053330211666293561389541002030346940112731636282314187175738162822774902
Row 2851012778150659741795203953725220511440326658824493568104751224129494232211582410123243040454054184847623792347610382693257638164199255056102371921482974723612095629853266316755974791616
Row 29319594830264426137810712480322558322717018702963327646861161582542951398174631242145410752182773495918804448493226705064212636182089552499531593031222029913301292038612641952546142520840
Row 30282217663963496658723181173948315061186376217315249588853481337439434344963470562148677034815347103336761892245836962731527954626944245533338755983416329351681925466554171813401375422522355
Row 31524957212916735491397811524407219723981176847033259122953971504562327114864725206165464948701070246228831823471352381072443321541806492425501887447622385944272389256116863618195831894179
Row 32522846742903543332735524303139713118632194726423429031592576962082512619822528574758409542136240126395753435858283932358545018343018482843861320224439825053442312329281732282550318272363
Row 3346283808489143753648584451148248326444062310419519908115029500856383414328586218122832330449345760503552165262861157838904669468226523163122775236427953038769510512332759591626117665554
Row 343674209354155485492527184419468417523634394626135212183512815680409935975991874596027863911728189051433487180554045252135830771345773256226934909804953524246142898185438254732313535042831731
Row 35349537046912801615141921707584905397516141565333323755001055799576935957784721283653921618469032173501825721318125554215884324644952499466466532563568464034161724397265312244076451992
Row 3616711229571345066201331319638371680502045574861157527725745482112662243348419315498105257029142776454135663999261740174991428752454704279358653459893701171450092257574584502931854042952561
Row 372888222520593939279449737151335253947143952555370522395800240850325665244250203365415540295622472946124650504740154944160790211693666484139632638555652975176426932485731197354875530438045185194
Row 388213538255949761566218137041788312750419257754357509494320223935490546593490420238351758145035653731936309421105454228829312991484619074557102756104734185723602925163171620192574273859541478
Row 3913963444568052315201112927952931206558895041151821761972450810223878306420483488179739045847472255355627412108329969535864695413832653925333843947202694586085310197527841282483380651593547
Row 40585326465344375724934066329230544806539935355002985504836372502973975464336921244510143005531076108318351558488999351044741363944482498131251357893185131851883538818217225854455242155575429
Row 411064324867316415481226123926313060279715194053190125916923482757182328602545500741781733254449953905512834503264684287813891932355115533479477627911091835558816285887148818871579183546433401
Row 4246951188240728722920495118678244079531711502763219525384694574540902173452088122823554693909241195657961820379144385220248656261626535825455771225336946555414518141727351056111247951462284
Row 43999274565135349524741594245122693413241707263227273324258208428764834330824534883849476349055835818501530624964129940604990586354125484233710051935460544172175531210484902564353069852519
Row 4441394293276316272141152653227231344554757843078453843529770732554780304442597151649267628899603723179160230292775312011671067588327943208140933255931275228715714305937153557235544228121135
Row 451465507018493114174547384073546852846752496330317943663437016774561577308637811507583765212212896436647785250278855893854253465922331366404971543858711498411223674801590630317015834864746
Row 46466842662534505491714741400328325165070584010344322449832665687490142375125477257343237113945343142116817044725165345033925918702189748352175329621172426394521872266497950876322451955664
Row 47481532044362152556557447495698741452442223949011814231216023711114637771006326220349515448246839295956323117315128946535470133086820269035616172316446714540379671959348256956691494
Row 4834667547555495625420330163554415924637274309314043803778446952475804537248621526101549281671505258953629540024643298893281039725648335835973851373115020096194877317375932564095222825023898
Row 49159913645424261429210941666187472310652650202019575459599216052817358854553189473814633808361417801566870587437943372377253924735319620065027428936715213301247351862503169213215022229641372610

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.