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 04905268454821130546736192534545757921336356611901464209336548735454118445672613664653562468558703143823397212154708316348674700332016726884671139753221212772816391730841410493241943743389
Row 116422827965338478824973793296056433491769105732259821655748401829132935886571639792127164679954757814088270120484515240274310855234535121538514052190353764073613298928721246218823741699
Row 218722525206310365537291723683705327333152825945295513421234360338092297451059044741351457385138334670162919493463335235333501334446111022374836494493145058882131467037035239584383720512298
Row 3191557042193118670418922684213357523457165735851980234113113253378365421177616356433654254683011013729403715396525058251912831870480719913175423756073570399335443847366633725319564755125839
Row 41345147919044004223516563870576291842455691486937404928515585416475685237158325152549538333023890398636571925479571231846940513661318224864358536121282890222921942461488016455641105425085110
Row 555282325398739935634275225723941120995155827122525225951834514215191545331856124921434690216159735048291537393389595839213144187698358794242122538547234429308558845969494137023815199516602810
Row 68682537460120203513841831136749352636518123105900470117203974945432247608516172426413037641829392121931537444456666832119930405497588510364272536451862041113351961639204542989723206992
Row 74469564616031553838403649322716238711101195001239150584625178816675011265248424568342018665904218995250515614100952135040403044757394951487718598958735551601029390838174482397294655342641
Row 857663324211139305326314422295961210242721289594650122430206143257302502289429055413238527747919285606287363501457192163331517118275215697534786450702592456448225817400656162316220441822052
Row 92426378349734931833217812993383225540372726801265698107035703465542385136841633311313418552178254438181167556213410144197430920374039120443713242825439515663111386142382664112548851191475
Row 101806341234365004482644121972353734825011998190456402956584982942511991117548303023580878715305798453839311324488563650085134387753075501178519512663023325488290840023462486328442449855983
Row 113921324956251760224828164523124515251382288884780723683235156260837583314315497325581195395648143173319326914083852317912739139295151062079580828331084544519923507197248543207162323015588
Row 121250416689316694001520424416247869728403009507127715924207327431887237828014300209616320547762702278529622905272117204098065796117547913327227936335453531154671302808268278851756583236
Row 135474217759048967551951550171553336834576434327626684206341823643284160441152312073578398252634135815512412509920235736129661458115704248134871420124581947430913273442143214318281966
Row 1457910484260337486536884196642284756691617527331582281146272427232154941912123248233234685433458536295183459244801410500976650435137357915643513261030443142414864729625773397955963905336
Row 152445230134551185392046190345702440373324654783467210188046851979183139903824121511092496633355724726932925569545744648343256356022571423350223065591849112505268022301959632467676113752983
Row 163531103173551552894272148983494234951925792099360023151342885455465241724101474254692657283355292080354329959971928368817503099249342094832510217003420387635871958301098435394676153047052943
Row 175348426415363143703344958852755147494448495178383327465774100577118413954691379304748691979657463536975319591732605003450858852342003475310819925041161017242073394218523898179213511865227
Row 183339313030173559281055387533304188564047511699426200775052741402300053637152505538319201835302665046631317240046918661761418283954522126128711431102193213072321935185523153827324055573374
Row 19357144181513510177540058347133189222446754218486533664111589171476655709532753513125011431497452751779255259925677146385997330324678173156639332262288194046234438586557582897556153675446
Row 204613189436118194932472620461337204710464216102212112505430043762396213814381632469613363703932358254254327564327731133281413521237557138041508379221634560368082743229041512192033251849435962
Row 2150924278117262450687154981422454021603435834522621485210114932872147157983247301397337114816711723506348644229474433465368348832929824313353710225432537470223555989356239055801438338763142
Row 2257671505464588020745226402826243055286154995449015702352538816938124764221720884520472220311544154534214748462408346547052286425610640183532537167734655783105165722932969256403835632307
Row 2348042752309059802814297343681861218243721645617347423404700348531422501114383123285120561955536192569541113433163368384025712747347594336361056140658182111134524345065183859722391495254374699
Row 2417183924412322361891410102129193165492331021724679218733392070585653183413414933859184032754220941195749510334675886280232223138402624821465453480150591827857725844515938172679172644932744
Row 258032325266443361955121892116256623287183215261372444927352319239148973854511841815227440569363549784370428740743096199951035542682121496722235093343183717553778180178559255084367957453328
Row 264685520992213750585764255616804208109635612359488919631992845164252991393110251512305263439633765595357017929734036367442244957228628392187581846792073211622384578104566349165022149251962940
Row 2737323619492633449955323027159952382887545643467441752327313152653198391441295283582416922067479025877525902832719507644234935220126145540301349054594635287029814251386027612940514628183275
Row 282162492658831553178243001887279821100712004752545832358110984409515648972425565353815577412454921727354123781358509320612723151811466434454612340376838192757285643297991583448210913731294
Row 2927071500117179825514844898375334658361680428616424350118815803434544616052422572459166421986512635231747206154511685730474756492055103355242746700277413543332175049411857185824615165488352
Row 30283135019583396107149544805880121562099331516162520195742914139565658082050274341792937501715942007507336745898425357811876817395030759587746182384326734233397394143478365590183313523087
Row 3134284336245321841872578993546070632228373844161426861383217384944455243360448056236414003873649247037544311175571216023902717565173214971955563521315425408252749863719198636955425203
Row 32546181123502027177642342408508635245885413221181639531747391552741040495944881258365254683320414134622191349721462838463054541937917331141120841271862242320011493243452922764951225458475045
Row 33350936925502136529221780518346805989472126545594321946452976308434804964313339024482132286342018051560470137383315537852410937044179362447932137255623795751362014535656201130455985347817194715
Row 345099134514379125512803478429074013512128894208202213205199422842979119123748365344335933642272195322829315455421049114290157333633219339382291408859881076552657743175163400429138054753
Row 3581946334355545406055393216531016885222299676121640452379429039802357273024381933177754263890342935124799881463234920023266155326863768456385618345785261843783261513915932664206333503923765
Row 365068410291212222006562315247248025196296825554772280310382930471837042026121941665414415042573510400656372235262738792648226021564145882894264407014545253696210156478052115385275047012948
Row 375657123225785816570539502904800483925942179261538025354138370625881918405116904071907221842923752129425021294283054943513142039514802280653915122210829093505854164836291694570411843668244530
Row 38430138131043321732523022769208930291862266531085070305716052591947460237325738465367146338502779536621832519795159757444409506138063120232937734803487525318795419124453483214287510962223
Row 3914955302107056983308560490217254685849419115234835174935566817713018326711331576410439948222957041104322416912365434751813426508714705995185210672184396430849743822362513142633386143355106
Row 401523103351885848289955614367578354622370176048915361189410264305810742404732305349273651611672073105816345613529072619411902338116613992720248929202998165857773782130211134277130918526705324
Row 411725213214432579222451684241275468927831845360913251055440430694454407039893080139155962046232234131672393352701443315154105759404754281000537257355894296017609755934319342026543482428459283278
Row 424283377572533482978499821103435108157150954015192543634923433347253712375912398219945975371298313591078303035381383424112045203546545221852971875341218773096146343210529792367334916623517
Row 43280545431635350570041502595472129742073124224424165491103530484416112633373787237852010162338490337865361716294871149158618193429531116484493445843417593723222182303821365558408229481771
Row 444840128417004707201715425248605475221127323010538027585089447312471965574920994350451948083258213621243548300649611944101510575707438722304035473626511680260456375150220321471911432848501273830
Row 452815704195042371268413128058175044574945315095108180559592211238911153967391229827364165257420674009389757893515575194745599599618354271573236283232956548120813298172313904318455723544156
Row 465084156845465046550344095175685449475285124964289341044012872355434868255402400513263148424921274693382038865733474370341419433161206376155673782427465548725920188370456292691164713475432
Row 4749146713068194716913478328573544924715429942972342206914062291660249933525973255112316853416108514489655154598614655359109101048564518541720123567225253495558248244554727267221753003624217
Row 4853983143428656285400323631849825292157925205428564218851316455321854365388748364550890236651120841410155445947171775176711753080607395078684129215785109135916125007469613622677404018323452
Row 49195944133456155451458861160315949394488159728682600412338234485979268947303083216757581526462227502766195612459752123579539103182426734381746357710423692288097638333995479324424871209157701589

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.