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 0291052051311831507654042627447759127066094300105441431731967598440133543224723145822207518391573492015832530299918835345451024894719462426945294572771549439947185324330985430346401538
Row 1434514595361665385300058922104761152051932734640334855504945853335455794441789309554011573807479458171847291629982004790227640094562595312848373411121526228991445991365132437486332012
Row 27035205150116293788143547938725395079548651161342588328817243956144945744701562996873415071653320627981665298646711195806225848794931598951152882196035715139481138963604355318065230
Row 3593419284446410329774302580228502442793473302639205668484923581267139996141384245693428377193429227904056179926763084270629343344179232254548126038994304233340594823441042405889178519535736
Row 439440057161852549529548434560516030650594892417749215254441879057345606219330449133244975453348651984103532161791249216764746311649752607466446745452529955561846451052644629461052385521
Row 544542525143198717144819153722865948389231625874465311883372545243324501625558925185063552120932481205828555193139822224086393930461993979236579472523721449443726729239181063562256538195704
Row 659735427311332095525558143997112574338245155837564987540528133962490311324208346555482811189163235971216272851085091401848189325303438330636794403357908293402553113571135815536973971
Row 76683124835299433862585214327562280227141202404391417735195404823343321214765537784613703588246482754115095138490621306001283241431101063135931744035338345954042582353174416193146941841
Row 810451451961472040134860195612995023196658434145274041557764083354333815467471367952695903169620945004348996738324700154152524675327313730935017140206415728735759142683812195064527857713631
Row 9361830732756429945714947467457511513042130453924444333773128611032840185443621866122427445440979296316294606364332912116459734712327411355160010742088764585439291271208855965552429534233544
Row 10105452164873440911532655387137883320146510308905341303653085867275748495926575339653242241811581157321252514626218964781324949017671479366716583559873318233935084561722212355572364981
Row 114685105424172571477336024882927242850146363764142411454530123328137613169127129936912313833525825156112161550734044394359539083222420627517335416581833001475572372121125970271252052939896
Row 1211628894854480937453084325585827821266158913698764504611289539265618568049632140463545442120313613822655885306832303902447347985709300837943831505182754523119611537910764215672140731045979
Row 13444731601923464937514436479823143838517348942569537941901734249740073482375023694374238710255069463031035592179442194204445749941793272511545276319428964691269841933853164546174092271360310861899
Row 1424423247387136834298310536165695242115902043306015662309378351043970774497959145583042634241434041971247220557312672785286659851927196457252610409647952460574920144011900303519130327671950
Row 15573365873438391361734100157395069499150322385069235341785771221458204913100929947843798214545872434600013954473471385258829825755247305171837394127283639893553107644904081532933579802657
Row 1629922041337321173927214127466649404192434302339239011815995979489330383170127212093919536120174075430717065746153721869394850458527793596756392989146241982547153817792426136232624403
Row 1759345577164431734383391058393676483154663292104646535774285417942571168548582881268113847355267541959504049505715735882137473445875131592241252710175725692906103717812623506118305676153752492098
Row 18478903252333651448330463512044140352711495753397221113744535852466820331865321328545692342267459838731475213185437122994445653355340013974293617081991349929162836169542593276302819511159
Row 19561210385860223021925051307483613614421409515262210619461923518409283953253882267357527835662628854531535024239133094155655954076466739173301961508842194481400142315579759458739891266
Row 202755980337043159693915095197480028554589355847413878157654548148721892572711092545321069357273369203749775462593583332362260583330174526108822933766115158992233818221215995384302857593375
Row 21716398153397143340273331947994343173132932605825390240953792343539528934884448515346040515945568404028112211934430630771532825559354040129835707243835264549271162827191565543821813433
Row 222079343649203512674264447403461148746181756247635713338176326165404465021885804833105338882808734135254378605204505619355597358241913258436640522568181255955522339330724794554109650845019
Row 2356659437107483022268899534309663643185638544033903522125523781053551530404492495284285155758451401226138546561116191542557773514108493611577735337512318902596212010345061355154092229
Row 2424858525852200837762312343511062571068542315844878270923355539494948251291274701220833571665166656885644815110935048581570585840181087456648692496216913414052601171721442945138124173954613
Row 251459130657892691825103045775358645484768524330944161307210555882455584309454163534584311541046213253909131173332652111456511248643004960310554313380558151418132957731540558319632239
Row 263995510522753771445956183813700510131243767317052121886345147504800426754603109286545544344429734847895916239863632202723411894203911371622603419994315633403914377025485992252427955366301
Row 2720235227512141505145268731462510320418114114291539981526416726383356407811355148111110042927532717363718144729553430598040581248513125702200209147683632245024892207129444654275426561543132594
Row 282216525041504986352285513253709469678780614032962318328791263161755782462418524205829119027882379586030303367452934643335113832783765566747825222581831258661717351552611351384126822604783250
Row 2951464314657486663213879862504629311523703574492345772937128625344185329315375037482724313229168237734148521739190489818155545757389631917624769303125975651478423534502402427014484345137
Row 3023625223480917469463449433126651315238647543522177373149295452501137396313397188664594408646943310449712752856342552425118309459642231657567524612498435350072060284468753131175230533324883
Row 318629152228591821452454191255011571506748905044656190113832518595830195422984079155454512946431545531033798146999516654996153296813243704278054325084527433392593637634041530564227475085
Row 32317944723896439458381647143724613056424719932160466816361718253651183958419328633968183583253395757628101114424396059674036421553562364263012071215585445638435818142223182637374911888872273
Row 3347161785675289237548571489543510921689367821134910119555052509318129826713796935418316173178816291059662306448552122087334310893522332421622792422867783604618167337737762899455047153666
Row 34522528814427278144630653009178244045906929591110104563301723413672515501914584989941388322601256448618214063240419408338812105545226055481992195368733270715565179768222855643441371267
Row 355973387436145514197217881716436936244458357391671424682834397285487499955053436133035343651169037792714834347215974621365457264841933726245033315476151143134902599747142048228438238266000
Row 3643302407549238361518225636161136584355544245782775495015381607193344102139570749750235778341433854655921155037783293169117710562569354424228371586355622581472939254338211500624390711263014
Row 378267611759831494879455325194323198422971294267212743683168365618943389394624501588130842084647101125933426661357260615055067823147543133638151144490342844959831080251276817843382780
Row 38266024625412414596957744090119776528134030654432215083426306922651880165848834762415126753998509920979717452045592720734592483820274767501151564694440428834385338739483419539216784695455
Row 3958314271051103613344753300523439434319200026214589263797457838311821975218446463144583239434900559354852772804215526848763746536739671038563059594521292477364925883403949236912344632424
Row 40178030164231548287186737325959483229653592953519328181603466936722355121222136011541258420773392184132727774994507467649762437594120612851914434414353312222995117214036822791484147413484
Row 4151745426385377812441814116234345214500017352681991254416144007558325544193785265695515826444730224445601147297436654211175197956654322561115742688323498956242163490192815792839270720833012
Row 4217184042278418022026389030035411803570435365226465152253283243812411487253375956372315451343342434313045557844356588850643001247324013651590825015039527036373423183533803006416825931185556563
Row 437587551093624303427885684364518426423763305195233171726166455255220401509151236702118381925871735144036147113491177654883233476714527282241364902491229282309299751825708548126211616
Row 44278399547552651130836953086574227585259136048423358251283583425542866230120934184094489620032964977397651082961416728021967160311862520533032722026142436881909556810174764128651515948431876
Row 452309105958739872392640557315863429256036733193595169633864054192230226947603869280230812545239439134117091905298117832427240126012261229501753274019441361686126229393868435635471512209
Row 46545715373566239931505658481649463772350552241718369045405061367922505751189424421562188362112851697413615015650256141542298136844745846342051313889328716646069256423632341442923178166440293345
Row 472869148616236223902166756392572146025812544603984717160610504204254352961991632141046511009179621292340506250211093070324331901453811474122282752235629370146884832122719244843490212904673
Row 483027314552692505578018013117466732353402564141775507251255531184255834845760100121628012303430648474748120725283833663218040775190197519491984385346754470476742322603324178057834824222358771250
Row 4924575262529728744945489349858516065206394122404406583054458092733400611724698260253105276534256425030276018581645391310317632854303523418575619434212332733396922573736230650281063339321908

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.