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 07411935674695556352340941078549501595467834273759442110873168106141383892162913975206179018074265219731971351010161141122329144620885298399538241059200222644105437563318373775267016904873
Row 1248820467842964514252061854368745733656538557783787729275245415930529311205732731269934357335438282998267543922414097398024244548321240822984171720506718451853564629571458725794708577
Row 21363592615745606555052966221655267927408721975565456241631643343448079087531989116420311283461979135911443424474567448287059235992498390234472657387734222705472752201334651129441235879
Row 3392615784448231451705488437239837222025499240674414367522872331135924174853186711214066257946361536991900189849252320535576853865763536446854531751525636387358142913145354181964311552431530
Row 43059211267691531562659430230211379318958794963209213856443622221746251531501338518814441124505433193757558854713907393637281761214563368543731749132419337821563958465253045576210536323340
Row 51711854483115565401706390139613032547438395128133042392045219534439621594146510992210121943162501381826443497242913053282298520051392565546262887104434453101461584248765554434130385817397422
Row 6212719864443823225138452919208251696231181174447594178318917721373147444326262729242309226468185753596220127727213434127283234454723238610562258362881215157155426025468575649125091957
Row 7388536211136212153414731281344684157420124577602064280029543363138846864927144324532272482817075282491640444291365662944670122244445665120321615255726705745981522948539364305341757273078
Row 858785646250827352112129134131849504147215554468484432234674558187254675290644786169361927322031393426828891107340742585301757481139603450165415824278747508912281778447558785835106047655228
Row 955769098225556194955474656179117163469198437272293546136672513282816562228509721663533197737025351184736583857747484527881185528874747935200177437883425481043693485695483318132850577355251532
Row 103321592847061499541420801615163142017532087165825403609160135442949841195469134164724487816483546548446203599497751009522307408444254594191826752709861929566342292680363634961978484234644388
Row 1149024554202432198352519465089819841601249048583739299656461184211425515160421125538501579414520755644114654281202360950450392409556019014442159532624114994648525794543203929174722748563320
Row 123559464838542671435423613031994515062118535173212071410134036397336021909141326544090208757958191696465133023417372723201704964329213964752258545783555278868445795404491612484095548230775206
Row 135494522426153111387936861775156952241312535624031526248333753397128450502254762427957645702953645396325604920298119804485596461729392785789350333575309421458801173435133123034788372021043192
Row 1458624875748516528248842725604471246930193132121033821053241452332793773253563659165291592528033849393538861511202912771088428868630592933345003142851655184551748914220303634375442702
Row 1550442581057180141302417312342001940526453334888356241321357268637633866483154861515592721301140783375010693033436635443768446157637157891222202451074923568839243928408726830695974151137355214
Row 165955568027472366452744303283528549843059175310058681932434730294256198955473146319929341642367938274889398863397849142893130569956521726356137252593102945411895517255854561874260428932813823
Row 172778491070446239401059369510204500932428246623894339736232989347934972299146603820222543485184440127121327243248364698399755727733054429211230972275532463736175633477813081267358528072430
Row 18189428322905558841556152515281003746393918355931813298513514074395191346895807325782880356625514384551424901236955605811951544131814351183737104024448010525756166228265187543775117344846
Row 1944382894229720521752610332028044775118743365194262112723193489486269267641385184445137442684507455911109745519148829325553595312085770486797212091518165921866822826193756763059248852153282
Row 20482835795070344733974119525156144553218121833641158141535395594211124950270283451921935233727729135398513519934333169249348494938573790305227646489633757563833612309103214594629168035845125
Row 2130934885428648102253065995142023613686137716588522871333552639054492105257442310549541813595442336064061297946001041579579931142651366247930652104114945638705945404310729991753174211491051
Row 22376521345848346356214586352120825575535438461248113757693899467257864300557628593924149948923952385141363402381174731721942208997410310743245391352375465591513687272827339051674039409623372109
Row 23157820022263366631733651375331355495313582813062633530841002910448542143435864599142425978785557488945868721157347110773892415541435167575551581189459289182432562530164151922175355656785413
Row 24302658618535152389954872602500227534554938581426274539447292161444018202268399157522238612998141215633107162585152322797886202676385410804697369235855713935252358221989546238674095171
Row 25320416582548376117421731614516840784274510647028915290190148415620379458201521349279557653391553675912337416333798151250873920585211424458443413531278643665304142319351714453214874223015
Row 263495394959853119185010234334649546932414806114236530111963881407610120543421422243349365567444420442118377223315117248134391484184149854230185558954758546716984554117051242951379918383848
Row 2753187021193083255713417371082501956276950035105451566131333396173844878205724269420627809045066232351462576073655727478134573141280054713281081539624103054852843456450343753741288
Row 2826061903128340163972309089218442019156336623290377793314442780202316333001162244463066261129231639586717315786492243145967330978825502518384034303709520140485797384111472182514781102117665515
Row 2940044564323410185914376031362824913721174240637872501553158163520370156221041229937593904433617745196596747861781558125382915242569123328214165436860005342349335382089490232514215959408463
Row 30966333082429975175237122517992528795665431145341410594446752403432952788246416052333155190521721862174472050271054024319057041804137440593959142025063558400588132910171810474869989
Row 3138281910243917923974131024151203022367175442302755744365222822119140619439774120948274240303434500026915049184719912416164615732337264756542604572051874822667189638152664177014444751493590
Row 3250295843291815835128215327624015125541787292656218727591575565474129275539394954912411524539895542154345305975172711423075609515627469435953481783100728037043512559136492974636402442021575
Row 3339654340536946658311763202619298261084524132434378291397160748815464362569335282519593128134387101840823408547551364787151846351645721336169030975634551219213556385349381206172257319531901
Row 34141724112971944538180832543983099694103847651643588433741433207915032780728187932219851271240134744151398411934889276923334209179652421926386568331929679603616203464523041000337257284705
Row 3592435265823944578714323404550720291252213258511282913281922657405517695256429466746343222273266512658711475473329851810338240870633648655605579308418454214114299945835087325622343239
Row 36325731824744235645318391704200013013438762290289057565257109641024690516642233539174639761709609163110435422065291936760534502681590545855380866488539143942322710882824989231820764055475
Row 376854558544632035534958941248577595613615749712465626947427174816929599617939761133340837925495981423948982269141546252624880191128932896324346095163216249743300512743385712542839365111
Row 383303525545725302518237714851856137855453033388346413035587333194657175316981147516953532621204122981498442171836885135762350949982169426236892404375831312794110436074637319124291197217047704449
Row 39138220354473284632292659382647554734216229743459738145140871386932325561595636881211524246662772588857354421709275714554252366526331524248822231276193924758696894786365777370312038364901
Row 404543323628963909683380302631521653706397415442654567612671248362428005682565174421701895708242440131225299116754081455450185705588576927964663535149684695142928476736702548351841303782116
Row 411751302877849354113158056045212593480103238402486140480430243105256732823608507936482365132954365251706981596848191804553692022475464038928317360758695005124140040137558735736843
Row 42535452353395923354152636995311321399648232813012539010553161582151512691407365139373860442752035607538052911266389037011159391531235591519955263953191931036684605221655182679528379648101666
Row 43247032881393670491450872766854880438224402510125359334663688336143359288265998111237441588265433463225415840203043156500047241161402532418444532142021483551467278360294946221657035020
Row 442099593137013258464746439159023371624137135601183706881481729254652834130712652819661116392957262066522837072738222629622739590419810282518563810732792190359895459304442563145308554451049
Row 453687397316444141060587140174048586745064650552050616723314125575419746002052971365335135808117527855143372944421618144664302188249132804219440441223752202058956086273086330247536442505
Row 4652793905562426546191934568258643053371479139553012133738834937223692349043533955200050882619216814918065082596187143503173151017433258325938292436391636156921562379833565972505538814003203
Row 474589573837284539110040172832274972730814761374924633489343126162783408323722564259316575402332913504594307314361466556223733225190928923517268429211614663547757112092634514629593864307823351604
Row 4865659482780161830574576410547133647447381934551305106537885749461541092993136392445884885170928964321140311147654270456748747503367431846013529500352555580312347252823245417803526523456014829
Row 49235566225532467310595744671743113438261115363414297614512599038962189283043484278477947751572294478848205415909332345565425720312192056460043483603431324028452269130416112039222654181237

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.