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 05117124431382973015624608149135821349291758661795476536214152262420264881623261883249293543216656483791924545332963963125746774939115549591985543829114011661567927728403741566117524416
Row 1450356038545572912556553431492619293711232409529959481541276116882829390120203024210130481638207878141649963924131432592474564326094547659464766141716243683427851291790540524112543502694
Row 2445518156522406517765371325933773475122648673124936507230954503550679354248361182251717374312245053214458417623391932448725264456889564538344782594813199195895274847631323221973811294799
Row 319215114393254831297889129393151494937133067296529265449384736747521642156637691077212254322328372353582169909501854642879494541514502216206674368823015132449981051715047359452029992
Row 456814085054102637982249243711982898431014945889516851941389130527923043126739248652321497154602358351751702058123396311538613330273633929912177439410683699449415769821233349520317091664397
Row 5550940603497401547610283394874393824492937114228251924200233072614590135591788298454911685487385171032663253354513205141528551431445702202140257834290151336054362857196146234173275113161466
Row 64745134342731635231025909634193335938873732153219223363530126629722004264212562693295698263854234773951549324933321620520838723846771571382516534365478210761343703624421563190536403144
Row 71588424446442714063302121884509546018122398572643551533585386466950024393593437594563352890618339513673504174629712881280645463795164946603595287330071972561599149673135610268523653720
Row 8265109648381599526323745765234417271893385512925789420402724681356217411984644179622733998147830341039247162656143044169312518089292745308276074553965303227251094030407449684857554230174169
Row 92389366447312331711347824618848335058865225838235358250813308275549308651328514349181329586154657221809161578324515243093571121065752507059105276487516101664301992019721945415547253675
Row 10277524725148359429445066540725191417928419910702301353426591814161558825701469418352193820764225250553963411396199951330732506833295362439765359506468668853813905430532244088186352302895
Row 114224267938211602128830383106550456811545398621578540694181743261043573852551786486524349655127487767015034721627565017373758404296155711421219230533646214013893377186717626441043222
Row 1227458866145133124813771542180342249922961807367832144476372724205086381744225620202128146211245140016222642314457152533310521426793933882588233703037013824295012737163553130535731933583
Row 132470814313846231062338813549823593179822474556163556772221779142523542735510423937841643665227913602490597412725380382628612448148257833028360915814458459242721315440832602164416518123285886
Row 14467040194107558911794519164450644221244195340483947389322862663423549243761652252447873312515327394599300165831333359588320173156164380912285748571833373444711337254616301072213472855574334
Row 15152698273620045521118652243461422226560529938424898138057278083835782128625328415613381874692491226113080920328185012982497472347952585368365939711207186158034904231452572342182971
Row 165343495826994232178512295966508428405208561536051718446852181222270293256893733421812064712464327222663238537281279563180312313432183329594855120942598465257270629413883145829462939577155603602
Row 1756631726133353991773152739834921561529188356854521832417327745074121223535574533056072453380043475420141633764703599253224359398437813634427948411377125491440391402172917810185213106721845820
Row 182486367416074455132370821282838546818141598565197644755613185110563850895697372961290250903294222183314475208358557134299325150795413324553962179735213278726943218286521465176171804946
Row 1914444930582339131903448287455252101666572858033682277784806467792457315177527750895915142157874611504593142333205312757171299544011582254576951663521939874853337127645596548825354213
Row 202312334313225741500814061142792274018245443324345353552120927074339316210695938641157400298310975809393190425225137378723293134118138762932614372229425449596531464311458715617965399
Row 21463420051989543611325352603754158622924515296317543175491412114692578422852915677277741535504143100328641524152136931778162928231344254355971943239236825682517631973967219143632703596345381032
Row 2215241790319738862042282118611095397835934165363548572433765260649942320352681858921562264714038596919384413619526519824472234544903822838250544089142870394105254367817544090477643911455
Row 2345372543146812082433740409732604465580698255301860113511503219173950139602632363856182446449324955331249815362048536528063834820556823274543523313983708161036024212799445622335266246927993286
Row 242980553440903425581201087299326308933932290128024085880564639125093787594345055184711735958307327902346114426025195254959622875734660217321914071249642074022471813262559102413717095681
Row 2511971290208539887626053685170527279556132699343267559312104439731053484549694758312643565058401629332167958055588533439574135296447412071518522995495189417263118569620964943659943712
Row 265577596620485173430966937452852151829095802484836341600304637563673570318314454172754131885105732025412243740029094350143790627201353504191755922974521011703817577342438673145514254081421181
Row 2728611074183145143011561624393623862192212102318288854561375588226562202188840275939131217564931853082738225624885903342204038522540983169146422124236845675982759233324834822536400622603183
Row 285256108341255916559248511252063174129253979225693677539422022097583517120433726812538395526091137519910734923384329275284235434163525461506143521195111285740085671483113722010282028465301
Row 2949533743129621104988262984270821634533524229119835623531526155210149641842298289317583609425138182734119522424485476826972709265945782326361452501403246276927072185386816794731243221050581948
Row 3023771149586117641822399317553741050234539415635036419223674451585583258837302538120242255764558507266730598312465393112553969536111157864601448559594395296463130431875308397618228921117
Row 31182427618693513819150156995820292447814632598296613873905310218533295324353232518632318425785940304013165470957517516013367517742352766130542293030247845324684208422904586133243728015752
Row 32164928095567215447140511204124432085122217122244212299156521217163168365936973764178742161736165636124488564102143332514418190438334731444385626295443481842231849599725762156497646315185505
Row 336181899236194092511641576948802079222243731951377244245235205449530281308662392616974741482018685383631294834494416126210363825452345215062351593138481832144523853983182881406513933223
Row 34163825091732598045921639202419535439263110234561216415129937192010304141413013104369881656293850124338125505375437852641375040864818956350426250601869586245934362365331523963729309712005820
Row 3516443499145936701227222941755115346359315607556065256175712333636191763328111053300298496758141318853158189544221889491757672824418410541847973169443814942878361910405797586034333140815
Row 364092318815973261127438024662081239427862518165428963617449349805018127223114495588130052272984301921129474391108462157251576127624962288505444846911975327512395385534944712140443892143884397
Row 37431254666351613339378913393381224590344403980573249129724508553138163184369858423992256015625796526610550731815826376817522363584554145676388551424692757282420301069478934617252041825791
Row 3848056361395237243102878539230314772249555330754706331749273588263832772587121250683723221826213556974582848585143973130848773928532341581227143911294155395358987115209850112298511234764742
Row 3926055942902550132640094388379736204070410652705293460423463631126759705955774158470557771333772130545252983181158451788488657301876255855520317662349283638785645330368352834713262658104940
Row 40488755205252309930633802247452792685913370550912891599958112357343855501719674204739336532354804110354271842114471547215351518529649383022652198443943378394346523590129016984289305917251232
Row 41578952385716381747665736434914642884180732442008427546284850254712803306149838154305425620651420303850764000335022592425414361042208743275813355128745048185348298740182163422501143625114090
Row 42401151394862468118622097598413752168530229323313887768110261214284824258154471894384369538261471254137127390020253475225840311891447598731791645455019132352376741812742399551618225652739
Row 43135623297481118935441252130062934148542969044332293240540391533314730351445246580817763730544135274730503054111321378724042844699854852321239814918266736156733040135826954382419531212033
Row 445161666328448224474386242551384123854925415165329125864463432710042781113110962938170350835446266923188835742573158335128703408413193341331633711142256397136337094358876256690810945321
Row 4519412954233142314892419332373953201069389540872926113646044890515039774399107244514468593657055375392938265318635933242331324935267108044241073457683160441283623302535785172242639203684
Row 4648933965232337328751220226282154346717104059306413522576384849755683119241459544130471346173941111826594334390194454582844473947623339488333614840497653734493129929344074490453891297253124
Row 4715362628375045965801173247795766570359597314251451403524737340663073140448091097865865429421195775772218529931739340949102451391745343614461616284854235145081325441051832091224444425691
Row 48346412563781189355523884563726455349231234561163521147527392841521247743505373744145094280452141526479435411173755288151014118190058661945575018819041902453359367238773490569950782626733670
Row 493989957219250704800285834364833152311463786328451121841571557051548861572509319863201425116955094280743831043107624684116350618455113623010263546412682550712711137521610921903553177325066

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.