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 0411043934864495529167753664443341240153018376236573153266551644933000280511682508295156520655666466016508454953435025313574414250721828289635674389530532130752811626555328311199223248922094
Row 1453232863767271728711112161050294945603785600349811525513459610151605380745325680559749944209084491580627354770443715927783435302926188931323611335336794817322688532344881768347947733970
Row 2325770240529943280365910542011992253546965539226245062441409213663364550530604797398631012451406614353052224126611612913412447555014800146221271183418036182501296238435112281294075841741240
Row 3197410662828165733012194152233755709342920713275023320821283981478922412312512956703686160813713794483590151904885317457474136505444042242214035389147219152277963993277541784828404749732752
Row 451391404522543927285389549042253324426739472522323440272918537951354754150951995096490930393113554155063089182031283197189527172060115659701156276431413866592935561569159611522142659301920122688
Row 51062350356713104935586664220258411911462883112863039475339195856383171822301951934180441375227594235062391498135716542500528095414974374777248710325509547357191811570249921410530433284563
Row 624932825242525504443324584684146737932755167352983111518043202039446859388395592419750041830404545478018814489521116058523098404623437191908191728461333043300312332183231275186739095327
Row 740642771887433116618712530449026331106992466849742977578044225771291722066353877341445774692241520712782789136526744671531441511481970406157884945983611598553152206290144105007146433124085
Row 84840396227061973425952062936545655781659413416203353734551144653721179541141715286756915183376725511585531505439202617381133931901561910254374281253364576256829852266302924635743760143924594149
Row 9370851141093429175428175081171658572730835402052579691317468233251865140813835955822307562818421485445351218874027230630942281170939334576157596122891309512238862227221013804560151026444824
Row 10394181338854685206655113014543316893015105750071312528919817252556823949024696545052771092455266312012283338181333813165469225894214494426292525942576854334612517441862063537808025444
Row 11492446611655567270331396439462411467325503184176240261550238148683178422663149305587489541729653051665446958232122490546308995013570846942373679490170013463627421058918214228132553063614
Row 121849488528956801931908493121332854754913724324757053975205571945511954494036117819223976542359295168388126095439154121930351896185146081384473143813743126514351735595647280236754943615
Row 1331093065100325463315577431674375363415614406109152381921379036341777156348184177451554316354306229728015975245531884392484857255216393277636501702982367591438231229331202101860571853684373
Row 1445885264815682521859353519282545482853703231524033275957470738785880490018494954347392013001102517239753092748112348043354538877434882457535832494131759776238328726719592203551121751663
Row 15364015838863168303818734460699460323811571471539035769145759539504297343394058325924532375364354761076133733223278417340824090591933822680417934744409489251482819501954003425174212773563653
Row 16254622755915504133121055139814503132295153254350452528461171301130171150226571841555359174622242862257721005108770256541653117455594424082760565250963542583237853463466534838634829456950993041
Row 17453325814879149925645233322465236139605452410551662624437013113436204237897336281049261341774361440171322904308239813994315153772421851596316222914544595923263297921781974177157715584322
Row 1854712080335042558414070322436353169251358093597408936671187504455562387373376542596781548339099914053651456529231002495145292576420949014702167835421977591133821646413759634322244240832866729
Row 192679352715365444148810495183490194449312242114547363247716503122022617509415642159219850672527479959302551575326725147022262443370729102918189618151924290030104716244653892889509917884529349
Row 20460962852825865190574520092389218834262280366175452093025434510561240506229249443445721168303825735962123470417292447934243804104420038771602884460042023351787173055381772125430365599
Row 2156831261510755871275598749021045874396211428741019309442893266057782668996452925523806414045371782161753704712873364698765936023961908453954461989308131874403416041491590100330912314176
Row 22401031362752302235488751417582315282259650344172167433742843533559772415363811701628305167635984883276049185194375819954672015029924442236971915777824891275223483345718428537013084
Row 23358819435685414121905799549246993100236195042981988467342528881898675201368233783615364941802049361714735775365322148631447250155111854312542941621250140541337488854023220212173238842423390
Row 244547103431251644431968348358802633130275022415645319720492290304750615490564230185582314956913595253485956745512240552995563104123494115124369236433553339940941391598398031591097389450671371
Row 252682328337236414651270875461459819183940220765055272605162135323126146992234572520250554876814263857304136783887277939345741174207051761601096362334694310134927134984777533151825609
Row 2656512007243340017955895480534132841259824372055149657391482003533448284630665757391452522295745981894182446052062413848363504453638864151230957826603700911178310056303811136949125392761
Row 2782237462956226311738184305247555631359166236521123947207235393051509550411119337958012058356229415995308844063358368117871854470212924890574917338346985989192146797713424003201621898134777
Row 288312790157131682901258859523761521830972423319066357036754585475022831333404941942429272813185211345120418502693599448483189554547133094354619143086339028385045803326512811555180633654661521
Row 29595329045859175120693215576050582582419454415252468547946643253233323282684380842504663342436715641496599737745288821557753113527580825572047448316154036902220515835703656191273913475853981
Row 3015617945186218159312118424648675962350681256282677148527865137266511377254264756234516724270453643068103286119217391934394123337444790257347364184299352072493302328642303775671250034822294
Row 3155403525727484857363311544516848622602244148815391157316484388365514501476192546142188939218216965846134271226211525811459941025199554156315921583592525721158787150237244785261219093065
Row 32256220072158230511670924135609284336564236285420037024837526013725551580553075025539433645144215548913630466749552119295721615161240720121313145196751052703529696651895902476681658352077
Row 3340692750374322457125950517942416239344192238453925421399475619813124591132584234363170118524617365052855335549917585724173244041304194837151402301726134384205427994145232571532952855593558
Row 345011187184698033431122191225702796236459936131237273924951480211237515129322389448341445543554763331525076332022876510255348173148337435334561419645795571257816379620623597882417741358
Row 3518605452347330124105532428954452177953354523532643881402674523285056772892418440825651391915399725694122958085448354145474482301638958924638514945322592357722804865731567524332835211130124404
Row 3644154445382155223165401101437154745967352413429355369251076143325048153513314404565515121924578446748865881298213811358204758465443524244475369591545143453565652958346423791163850962541099
Row 3742428644788197319513848025881448813232629122857095848357944939535173192641774190188328751924262885253545595679341522862572277050329805393896421122004975343155605844466111663740304237633894
Row 383547488642261244346632174935107231283328221492328391323221193119316153989454916962116313755751630343534365301260356674855127150243702963102729623842306610195931308330716935488251651774556696
Row 3944727982539159358755435549453854745362327363554255226217713791284544614636399253725124159218201048558459382650239236241892341469052764511395252181809156472750551304304853062967102484955271367
Row 40798281745933389689570314951369531638465381900165159681980467916307134832594106598228595829357552642077387529428795103263022465972449839563177261051823692420577241162187156125899443762153
Row 411759399210571194349913592499402987332264954990306910771151110315945994513720641565487739692905563849129324562563463172131522663812562048343773539532882458109034991352534481283431285053471
Row 4222235772659142889271851813205614255557104988360434314924339549102701513847247945415316438557185074902543527583738539081618663949385052815454449948501860972827646105400628972045155376
Row 43435024062451311056512123254039589413948468025915974399415220364128141162258431936167530946774780286155893881434016401272272439015944174010054102315545935955538564812304595344459259521670
Row 443946374949624440553755562348633848263229045711337624824934651538817841220385224092915247241545456403652499791061350259934974484418765371198326364583133850793901917158215434711466591655241686
Row 4512322512490580038343352172813212170579269940924198471344634991847471516871084358010262571055364456052634106541294227290944313992339193460132328419251629479719011510426520624697265654754098
Row 461273089483118591490184575835149625159446559532492401145933735895541468488637622904790275714893671993554895559982059084148444151301106332464122875044539647253040435849122549599014062023
Row 4724185419811508839429105623435775131842426633038501022245611270442859322542576292330714031488515542960870182450357142871055459514874191458011211955431910014628181232501513432517054725104
Row 485962318670327501884180222683822470029752647456214137825975349497922075968116840040144419122218202015384618302190565110557215717126455303763360689109241982449210592657515292842795059842
Row 49371112623234157376534722972147058484853404221416676441822222578033024471336358244938606262838723046510545925455513452432943664653513810415705350616775596560737503075330847565816492539622643

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.