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 0138012445362011428959785351682823229512742026382425593334229478554759842108347471154540803637921300217239043037168459842447495256841985186458104667223835439149635846346036505513224369
Row 12031319111925939368142731188327154311371826536322043496171630013069596413591559151929171544715346674427944165463170242398206615815839332421464104269040105615787276346512738326329263233997
Row 2619393413832664767328218951146448637522275543819364712496436279453524263472450526465596109332724793391877246163972499127628214800737579755973591422429873072247303924421704916510011863114
Row 34912391028416231341368477112725870499163920995252771681320211561806223954647104352211816735812256278530945917128425418701449374356336555261223187740072326438244845920951509576410624707
Row 432694479139416529644265817265031704092518314401991262126133497405951462521461514704829254938693206329454852852560733553842894582982114684811301257105941185241875142387666012863358577141761424
Row 51967145634272349519766199840872823525632473241249947061759515926865635430438425381032969103227652345397949783334262112612229296836682746470942433229318933012488384080722423060266985125364266
Row 61132813509739911608520345503578378911552206941218824811551186832852854392835202544356931373686582317523339496894154454271486651833045272055645996370932383029192138875271585844442492150254575405
Row 7480238674676261153941883646196535431126814183307239655778722254212533687574452761694511125513832756294459715755594537411745524121312354828291020613420198432811784134887851663501431933712998
Row 8975822515609304614614754869219341255186420389258754689500157394534492023155175267411894621166520531544813817353115842457591243345181094273250092237200836015056600376723405146533335
Row 9522559627615593257325014664245163459957154191269115068210085837413239341624721105130412248682768496029671608379143504347471122915235447920390716054157123039073793266321665919245241733976
Row 10114656065762501857423811104847733672275678301512654437418751446531665314536462828291858171604272120822663519053351486431978717591860580361651754895364256771764530636205304224476532947332281
Row 115317320224021482386623301215504928022125565945115743841740298940044163110423674014132277836295608219142435064145344361602343707345811015662310952763447933078391311623830210747419026604326
Row 121701743391855073176509816752164591568583735671522304717643082333340627461677363406971048043661324825411803249144336465138599934421914293841185835268376233733095827357214063259339943482585
Row 131246394522596732512218415056845030296930642252141829782911417410351181415849902932371458398444881597429533984842422548529437215337167246630911921399422523834340836993031558420845455892848
Row 1414202162290420836691526556927663195667299435145296542834183224012656316244879627683057892368608142297613642881004427143312312468915055099353604191910404787143947175335936494718372427
Row 15315833127651715759316911276549444516233220052405349194746314188417035922431424423941805821925389127421424580521844009545124220842564382622821413194626528384086460151485173318964052119
Row 16599537812863436022295262325393116732109403650872112580427447113073445047815844244342202975552953251439494947473567527135229034481106712243972656178449262393515037504969335830352493431118265720
Row 17105824495605590419954993116212741002138244564909494232745312000400911554811142909353321069184522454726835654441556919612591300548614170447656525290199309731157334627457426405777384017342744
Row 181638456147615047310852141154803565524833355521490675712921652363341725143793339414128639372365499451293342281357013224405450463201162381428185076542935421119206110148072890320318538663978
Row 1944204384179341951718182682656831751598350211003552198584738216965820654915474334231241532608441357204064688286715681002420627732228162159942555409554475432560439145615254788290411111334
Row 2037254695688156876414761554967121258917705242329031514831053228364625644910289311382058336911173168140842187172430366152743211763233659631779271140063446053276396031261954244927573471764
Row 2133613058279143874822485106252851242562545452914270222959781948135843514063702118465870100611512717289727895339366424942851553330692080254745723214494445262161012545971447268367543701770
Row 224091251355104239351612266148133721281903115042035814544444642431312132751859485392538049003286289536475033881492425416712932235143621287322412733518684110150902294441392112515527723662
Row 238031255634232361932793822173065586630334984366304649542080368515274397142388554335503357001325456145705569412850861075178138804030481637795710149710552701125627431411466495425144654814
Row 24842581576623063073496446612264572510794010367940783088363565640334143614381977588246304314259252534431489225459641547323757695471208234546574781288833830615833553764351875800542948444936
Row 25133417312810424819402229174651134321202940231832326454792129429815882053191922117617313020296540311311323292726015712267931902185515134752687225453786305575336451662906487953102107123137975968
Row 261113166815161243535356786742598419814918364504878507691874054494400338654359044078174129943262398726024414365446251091440513816035670399855614953198819833192402558784612744581718982057652
Row 27504344735545363565948323564165020220111143556721144274295995397636943066354543455044700302597815493517458031515349698291830971763503899943352646373823515401251117254594372224194792454827
Row 28472744181341486410813553371319353822221257662934740282319216633170227857720661516572437832748437413924257539367450884277512298939591458364727054277179964646903519560226391418179156992091
Row 2911355475568030073239573411731724888454281425286309232460132464639784833131484221232408388647953699551381346204972555943865567426852584854241666469014246823116165735115271179155426925290
Row 3043794558146181501949712479265333552051567119252513362054085182534249973557575119325734159043104132564858634655109832223225219617583717427936912619158547175145530546241558375941584960219128941624
Row 3110933537445940335932563452504772571442079331072777102151874654503258823561155456622924386118175868512165226548512268890501243051374365371052517462376288423859237930684152392827185631689
Row 32184033447807853223140563619693185338374539244603463633012632235436314215272353406347303995386719382553145250414501379110720425614161007589431933961561653512418278723874303828232441245111
Row 3327862701192954574436599357943189166242532692539635657043433051218474660319562981994208574759431413924781492968757633672158032182678376716335261998276348958684537142811721088346744783203
Row 3415901714486559437264509157439492100584722251236548951865493514012215628244256476151766591627298239142886127311040633475451849735309572211685345581322811681634143199256918272614381158639
Row 355762480568540442999123131395325498438352997440410996392037493239989951462854909517223914365652584555367562372561049351474217257504103963178464220127775667561012728674876502130322513391
Row 3612006213249641282715325985106833404770424354241521794409627435941517642195032546910311612398828044691588565512450454659783919516055335695787564915238241191425507429865094557227012393345
Row 3785532275984748324724297312174188859045012196830817843181467046583613050495314461042390302549344009126027083600144902471046933898337335807061421618373353019013122484410434610323330663861
Row 3859553226303134485774266286537357511215526241336214884269131031571470250744542313116116481068593130592797101116601868822248826697513772392876488445263485050495318590746760045282724345
Row 395080514713555446335366078532759995442515943226849601572352939633266055347574116514627345029862029487918385895292019685185322357772126594233222722209182749424853253477049346055601394406
Row 403288306423842435555386358104010943245377914673530398629001454247646412989427728068323107129455312909338018999225508772172334221341474445142871955923574438531615150121832400320032032209913
Row 4114944653264320253425173966203226322805727264733429948385716414126125057892748462827214091316250293479423819522874266757595537216245811813141812921114170418645789841381417065806364120003110
Row 425225200050901957551837594053302247322384515644054672368349986414893675250516025682364213712343312840871408445846782296434770728533834545721210082027721268136073781219737805520254951073416980
Row 43353446002340501220419134375676813212944661651358435715645928144213101552482237732542830214614432875214934001002152931994066182095437434990364117653855549155250653914526152204606354341065298
Row 44499061354763886318339402702790506742950169941883232432123790888341745166503627884030148912085839881506631423744142014873861165745121012128555029054115695105926224637874698219344045017
Row 4512992223420518443201119389720239047113269744222529312992225653923089560738023897322432651389544337518454505141980181117141128232813962206289316341868233134253223684101828678242824063469
Row 4613604034404127204753192659233517108022403286387431750435732182262539758472079226258702223165741301375216811033859177653117603924523912523094342209942414561163425379579931252161526617913
Row 47522250285236002751154754674140168720604101140227248613199786245844840804707166560559503135223933221569705234816843765543711246558752653484337549363670428625693782115013844183407744995773
Row 48140629331375610274928563075162102234191779149396493456484697595319427496122062390593618801501399157262931593413610681003335913353204399435433321148043341119390524055497331342025991640
Row 49310622424581570323291632227557341158204389624822616561562085736615182421424402822545016514451224621202386133713421633894285629594285681436316942354547293246115647596315058533502437158353202

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.