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 01901207757379685390340157802565357538454152434231587234521503137442955561263834093603273023450634834952304369531535384973359730285694417610432962283427259254568511312794456326253645269746
Row 15939252853839311976172581547124725188391831634735798299450061603197108131134702574264110049435516580438235272721384932605338207738788965838154263120892815140642480417095479491556021819
Row 212634929331484481128076532584168637182041674893530127983777215145361210259844831381687227320913631545627346641580458710092177455114504042572439673101529152912205219277155144537142224364636
Row 35497378450007475286564215994179144918194491585918803790539371884646695398978477742764306125554258903059127963612025977242522465274373662252803367436952183786510331613585941566845854595663
Row 43025553536011390471657152539528418221637273125954099584332394242371148661834175185259962138554513213093263355432010579652373320214521441387111913094106810452241295212043365276934494885463
Row 51352318153748153080349146342165359142751452574715554895899187975391859422075154319474679425140254747553231636501897209348365370281324604866563027111301518250858442998255411311370347132951138
Row 64338374114295631576340253301389642363655522057227351346587840823270648115039158453397470045614865355655533797473932605300294580133715166597611574292207308540231143431817744046111612913151232
Row 715231073131545650864542542688167215521356215300456453855282560555134083394042271198493189214854944122442155013269562134344375352956981044471031621233217811932688396648914843734446637913185
Row 8549115783619352409431591620688304747172519509438724498540030601238162215322704373019652276115612774103486413818705960709421345341565280594754692396170257982482667172846924272959598036805623
Row 945252187328047263141438441733572184051194741442241411883199634354852544821582256425907209647603700504380339252981119590848212619523048624057198502027297842887486965124364981591856224441635
Row 10143023625027112916745583714873747435122845478367660658484692395429411926854144755942468340030539412404410211365089354821144283152170869229442259429262514695692838386556493464243055005583
Row 11488742539844602398637495538214281073157331163458515159762676520921962894115842734766203547865515258428392618484325845549486833295082430222524369251155403183596534971007229145163426473734551807
Row 1239974454356246342231393424535921766811459348056773190363657440785467321522052954470471230456451527192528995603680442017213942421230627712866198731001805269853691862349143953176487051462281
Row 13435087191053851305654759945093475134841351569757402123364612282331746921742141363174035832486399323978519682851021368933873869104156815545378244121051365325547204668323114437323427
Row 1426844564594348872025548765343325173572111942392602350519314853337293330412933802363229351812677534513053541725140032824591369828099262830421245464857501735585669496111305351527828757451927
Row 15487239564695563243075390425592324765905568889431558193925377438725377150396949635230574048003376177229094722245058021491877498290722371969484047291231412363849768965417526678592823905461
Row 16201623332759308834273056117825604536452174147225464076411072326137581340250652964473209737343544290560011126021417431832573561571657621017395738932684236532351912948341059435357528839701913
Row 172912441383837716145691134237355650506150130013773271323852333887279347933705143350723442353215322405383363530822733349522433253946677400319001718280019271318138344193027529150294927411454
Row 18258245761207117413062887568036915649383155172416491653013662999284042542616400855814585220563930352625675581836305397226304699268652275716435832351501291245936622076424045014866308735033289
Row 19316681056115289469957685082864436063820365541122316853764327353183109400926193556236735821871457219611925100134630994692964269712692969518672021224489421941352729267737486302271512223924191
Row 2059094637448317841276495035331516353120634585307525991743514839523268378148693372165251392507820414624501717852905268331542125507605230019545284523317935411322144885873026136084324513443
Row 2140292471203224559573205495434872717328244334757360746113645345330156613064408518555933915148953929122980146044846924675325415623078369831784367422823318560614812473146450492703433632885209
Row 222246782210233463488586131575779325427595322423815525981576634563700211945043176256511649801233730597915294884974901471844304993304612731505471845434817411836101257242113581478144324974865691
Row 235183320582350314637553073017891105314943354466815155643741841475214985141377654292319277138681689258211843579314215694472937504617171871415834078245635376450558934384560363246035528116031
Row 241295253411443965376822533167342132131903144722387454407834477118294454314113833356472537941723475626041105268024074938379745514582455022223181112824104441573016245701389093213622321125946482421
Row 25152614622282347487343452619598243167365857107901136284826893137703793181052923795361016872234283615373233293742051733904358143634350209260431625388388459372322461686136965994585535403918
Row 26336074353515867943289198359265584134848153064229831903157309116310364281280844331237101245165606395515183520587538125528132324741539397421185216732372389613072268476059324603263151053463238
Row 2750075567480622802198561832913100359136513864797582019221522597022805222703662574426268429092187372926582370380616312186569634944917420440421565458510123056510681258781873322503741034392720
Row 281806187411554729590318746252762102151435234350439053421719261752414144545323927352150530576619285615184049164319374511710822229137925711611133941255186451620942070548333363588288191250284230
Row 29219453959893923555513726056385914105034438722704568479745031781391512493743356318331194435647663372264234284688563049006361479475822262157773485950892572229521215383439328518566675232406
Row 30266614081343331541453058392842565087667505211131326315085146713204740136052774993450446582017512886113110382241253658082631103850761638303839233741788182555692978366829803084507552236865954
Row 3148657068564519150045352393018403312441694124626664233565133041595242125515172116213851712019270124251672364418313083805358248551474414683060803339455423220472116414971894471453752888206
Row 32410237053914761141333763845361341446720642274861263656004069147519335603093343828114342393918322271899268979033192445534336781141847507536992069293419453727310854474217105259103816225028
Row 3345315759219558423400759374749338794687394357533896243434801300599890621064138432036964259387947613693794565232552665187239557033632342712771784127418802442280655304329376850193453399320003103
Row 341768591556132006301540214845834265496253521297537304920613794109418329312012944701100531323851287366216192513922151199226444231317454485165305549665205317541167945881527651577919114761
Row 35255861447825356358739453056541121272362110387422672078206091717406782499540123615202330158742865536501922791568398929465305439947802676331741093988440125724301556233846345427109287215224655
Row 361057172029682110572940705597833503940261929724423200146282289557459676902649546614161193860178033375292415573614715502266635675076137154228373894283031092261585911140313063094222718721768
Row 3733452322382158695007507724012382105637094922727533835781872386939608765935581323435347447630974367689137328225196158353504985471362867516152612364402113685365201301289741695600176542165519
Row 3837711807458740771747111037450952736236511185451216102880570536444767643530114363577512118992829188539030494576836212235722315166143976028355705401247450412694901214525951381528035441434
Row 3943735145127847222852512744942784839400014944805408437611397527750002385484714292222614376183424593689301420217982513149714671096141478402421463763473259194590294697344293546577535113675401
Row 40132055331205464044941685892250149573482249529418085904422111251852169454301177329336482200578054293436827106513312908594646227542031338431849073304818209457825761172099659651794344526373658
Row 411929781461813002818487852745158643564013652932240258022638448513084722157593256532077363612213489459644932593369682276427392374227117003821203350722617281032034692300215874881505559831961424
Row 42105348185941108623799283575199574043635201169328836882392499149252475458238624611338916854516452917410373236470827814785804226341481882844535854503439984252535483121776248121279822952644
Row 4315099252084211924782919565648925931549826691797428759124286244611023267557855250043093494556510732168522432668832284918447586938372512376010322639557647911930546814124747854149247145921857
Row 44537313442932409856113488108739050605281279314922144223394322231958904503853525416582205300322901754349515065692197250633833364367953005083511617225960233312822837369838383077235477217561363
Row 4537374361265846018342766324350724273567554825728337114123584786575034302642489148915379593915052357446230731349509139232412508540157922911162689197833553052168839781042585218785401154440521384
Row 463625114319846824434977212044061659202371253581524226144578412525712347958555145442718732006252342022557558154003436544033141483234954595112783349456733344864111334075422971306339748691610
Row 4719055272423357904630520340293221533821526244077572379213625344982369124863082223753003285159749525280293819525186937561882350685020146617022213577544655185973049303450304220540330364871275
Row 4841683976255219475626472536862110306850919813107280121115160265836467220048425869538141092563160640334933607108327463600778272320635000130235655759317348017783966178229563258264452455433096
Row 4917785922265752051859119134162248342195301745812588458111953368394249244451244952572392492843243867530625973985184246370339019714564411821953695388956833826355247239720875905231451621465902

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.