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 02059397136525229237643014147357033542206532788560549037555840194013705504878480141681996476983935394417554542403562646408276635482591344513891376249110424905479056591289283936406021164806
Row 1254594921301371596547891481452783912275284274815072890202488986844327338044903310238751633203125263119401242203666531410182839214151902387343916643716187135804057439634551548311613313043481
Row 282710112461554011715420467323883511596438158863248230625102842265314071932580255536832980652109418961233497139062582692185945652128134281352391117532625975665553322434595151256325693448
Row 343101200182499417642838286117031163879234116931951701161492627095136249815212180538233635347734531038101344298035724038494837612317570216314108213356534726419839115503465719931278506150915651
Row 4431623391775251616021604367541103158230617081306346631262720354200917925389168623403868387849878256146483925305252639413491812395424441745587531591146439834535810420196243284813464833352070
Row 5487839714813562435793075166448653918546516237210084400375038452524425241634235172643928644511564555913547464645804613382022463593170178750624607102023742453348274598204152704784554426884818
Row 6480627875457480336684535258572215215284235267229191257534450647924028274826875191434348903548302515544121335555343791487839995653979462425096252077338552674210389936518844814768275213329
Row 741633440326604655417743692829128650382835442417641673855471177419743403247545732489349234149403778640222513205111659819862003399348771167221832991257446247775042435960004731152514613113
Row 85537272250929192533135234905010406116601605239537673349420940153443052849233128213682318329884593499317491644581853604915409036932865301892328937792502184728845700102421578255782254752574155
Row 94591214529957095827215959712493783836504513503711082150712088334541108614836061432437611349634571297108436662718593954162121171222584736261740943695976277442893345182721661774160050283219
Row 1056723886324751753104625254153445517331852251382430755351232774229742565227321933953708296453253404175110042232782294619901983212120159715647398848795435247142312924599736033156527519729881436
Row 11180356944256293584658322233424211843081204499541027530629981659309027511004237031924478664493417984954410936615025314230218223427124028464299403643652203349031721760506113173339110815114931
Row 12549330616644146482924571609453217394490265051332359064090398159413511754487323643785329775033263919500954232809175197291431603277436247321534185541295246472173378233638471997338736441912
Row 134910558320831752289284921322757511136242600252136413186785364649553408426511361035362970347329021844114932912347345823734110569240143740840266543285733491956782794400419331436518548635991773
Row 1453344860383647154490116557115627114326984925774891541529347755186237147243603439171268355820021183528343515794094328108932386065812443460327310772310269648623966500948165710528944252352
Row 1550903720155153631671408311824191793244334349834089130748053358815485456280329743286649805376480531301234596133532025513850751994586417256816384836082948198231945557574650846624704
Row 16384613412226951206528336733054264227763456336308126015454340303223093249268117744453933101471230835652410323842126320028471334300852183887189757454664987422411501093437232891204155912053866
Row 17226445793354128880027972860325916193145662198514534239347522236651184364649144342116353374397584738732189150540397765779206438794049596852071433490255973283509370234363249621472075530575234
Row 18547859573987491355174865493490523972453465814852143600471226632336333279018864134366011434181265439615728392343341675506512522850206272251932481645476827494819583130552347559952617997292882
Row 19369917312580253950401818148640764642389409176051334288114155992631806595187148433583171443416086940344498751375232554387979350048682643402631211095133939085161378718752030473414130612054
Row 20407939481513326999113714173363223638013795933221946054076412134951723822425441165153893721239256452324367331287013403441519941805228322191371841172130219910544031493626434680401439152011
Row 2146783476166518991051290744352072566360451893531724723210449384643555241394166120213073941425245795010306312184917166736999863360252821802738726272010536054718317452625723514100331071958
Row 223298137016383749414109812948514439207081130733885364956484862814589457288383828489214083650259513038814738510624503731277234164249351401533369121665292242573193215616714865541825402321
Row 2321151794571350904802792104425276452344552510314145721161221634794545871138035018471312102165146531372920289522002510404242661129288154251825234837413096200830904584588046672042263420822472958
Row 24241313732451318257543884349578530932377319766918085564569815987125248611445613259324032776425716583355612665582145458145192507434023133462456105915230426200150545684933210253082821315
Row 252690382841554662215255521855552475627371180238359085504342223264200156133220901297363830332342855681102416955635196432312452415448242343473525399253063296603444256744694586152740973015
Row 26202737334844458640363002183531422065533745415946396764372258892451929944156653934241191429514481664427848473203340195734144947476425611054192718044126577524311576379449463178363625151182593
Row 2789765010034026170759112142375310282951546157524154341315447911714146441843703205714282126343125106570546654181383174459162591241831957792822169535413675372892293732736731199543232443032
Row 28409858104742132471821554960322319113085441109838723148497536041276371434829713850115452525932335513695901404160920327437011475928254947381320773734320839502574735198637506275343801125
Row 2913115271446859433400201715545356142967542947585175484454620961038483631746235638395432994828642090322954654393531356951592301318496547654511778380336723457163945722177621226795024
Row 301802137618274859266043221244443921154168440210991309401818694556143850282959380011023163019547141214833425448464887191825995373394557522349499729252835587725214270045245443624549673910315863
Row 311836158753084992156149427321554486342445877461244962577349220645460353545714818958400734942929904709327722424025459213414905317642679039643876468227984447462246314489665893405213399813369
Row 32371133585464580270044092916447555393172559358511379196727805764176332497774695225915541370169723212270776346910982105432418541324203251635099333742035999203249755118194616472420452973828875270
Row 3319252651111356919873543551539074516481425433028315126470250313944739815826479033553347587856894117363560337262497258950221387466514863707385314441456434256323081228350442106360812941072988
Row 3449193210380537554732378919182166545026702357523416241947337028893656231251203440355000555211874802448332203192179452353826215040236625734444180541184881604127032013750106714201003540359805525
Row 355093887091063208025586735684817897444911582741856310971714433698438028745070555971219424684297412633852676275454482511298543884086133475739621823410843531141501352684502119739750065008
Row 36429821751467131821603249550356734704593455627791789455425146324683531549988855762881533440125021296258047533350213842304425235729866582180202517712470159352202199414912564309346357151279
Row 37454323034560112743651151406273758221082561017011253743268639916611421426117314458581118451028961949522345025453520322543368375169291559083555332755634832130649952498298651181509244022884167
Row 38544228424117702970287235191156307450764824598723205170437348781017512756301638587942382998554959172535270336811123334112195956346521167103333524667410422974323364650639085418539155291403550
Row 3917022055779188824972149571727484452458192343241951072515242555450495933618805445208535391549400247625224589242456073093366595238651436411580145821317435939593443309176359542316319487703
Row 4098546484806445028021973987830613143386635683477354914202506575620388225920991615379958629423172527549262665468753862890160740493352461639845474507010444200526905067281221782454773476
Row 4145171754273344594224578816382651324911803292292240253903507353965357873932435954241463125312492566137459795729119550642182746586544174690453152125453785444714072555350815695037861289114195596
Row 425479548958975085204829563358152253804328513855690115745425465528450582969417438563626262610111496469234391297167411075992888943406957364525500948115249205218834678153726812469763409949423182
Row 434834290414142091201249212652093459012971404328418332373540115012037402155732525147270923894477597942903676463078571316479349494033137938881678174116745923369059784119824624224850334151030
Row 44242199617382462596752152284302441492343824111611011654483551893421131435801653584247433588322930483845312033303721831615408941125008357611321780912371695959768313281383737645667131228672299
Row 45601289648395267395175443017374353150420838864657308848864126332096847493983391317653566593221345074559913761897174981231512133780134548785102091515303225282444348330478564368229539141517
Row 4688022983146201776839473937378134435685151235067580748242794802196122675273963262134972387279854575986520825854308488610465626367114502465276841472816216019676344558334537416352738754
Row 475042213498333150205168301051713223399350045663815243757611530247722213212978550431864186217444325742795147404011353561634163710355003908544930744479293711943362449486755734456280518471209
Row 4844593336213920711023495215733402280447559545078570133917755129455262938022413151545502671223132823472960593424875606527282146024890869143361555581999057065556515828787845499532482334
Row 4952526326053249302935658444968805577453587251211506539419554441392546617495303574556812948983400358925141534591634661534181264331762848297520023553618127522135375518525642367333515205652

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.