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 0145445132185320139425203366130625492930279112434033175456413955134819523981135115138725330295283255528162724592336165063714196042562833171627604665495460049928563127361739821521165535404957
Row 159367334043494527821843251260481948441932274240211107151120471932560936766031555860335847443328267310479962813472145073802202667715943881280937164604179026381133161545481986414380637512990
Row 2200025542523212916421558860246551771376726305747049571609373030681829427146864882596637041747245680464437012717143022961884238537826134295522443172841502336250911213163936684800451336575462
Row 398227039508471303484014905894351521383281444518212412348415002601137217413609555524733162493113523949127852331359243172816445114202044744492514542854776473843941372284540615352730225943781656
Row 442502904788201241532814783126472924157246143422233958274474865749499736153583192835143462561191572812485653370947203967406320731592235725254984406787131163542770103714411912169852865693
Row 54216170228165597435423024267228454311505367369231733495624358845430141078244559821133219728485012523136348847324975265145398561263431559731159425178529737742721677538738485460397747191594
Row 64686210728925424232958524938364334265210322175928534027286119033523532236545526166571154711114277756394542576213025919152224385486553512022254520845054233236341683835383339589251744433925603357
Row 73998357850242156331558605766593457943769191290652418693687694302558735452745588428697581978133745423345016517923354198337605442360477927292315892989491829204348503730553908154156061648
Row 852771051735115402228037524989275657583595127566336521026114827273166288681047604786292556391190584057615540477918734264264548655071384013415406368355874985276013283994065512254930165881177
Row 97564264431485334081283371254581541304512154743199318941949512068517167663682341149325147568419482862179206846644013290245165069292351241707369489538265689480232220847464020496522852844711
Row 103894177128201068277629833051407220463590366527794752050961213556423899358215462418101033233887386720861129551628614618183012614043457950003861459382739511711108368517511255257192823503043355
Row 11225833064850348711981353119533243438109352712377160929578381893416927235766155842832120101241803169312655097441804308174854414144914315939001382217043159746055443218731833949567121839342284
Row 1257755303594024805089270618304146859227312054457889566044647602738138210425785127542746799013819246251895612103551662465317843321263489155610111428516320833282539721843316239659803852427
Row 13405647023766479142635631002378766187912683921496310114079119028992645166910173854401403651003087477417644719290474245832525511319604674478744117895819628587019455055412815762836106929334109
Row 1417743691225011425282450312764079340622895645941103397831401649310442234345304251315413275111687331413228236044874674328650735056439939355594900586513852183343956204877756841995109036843549
Row 153154253623802834475725592568445248492072151235835897547117404172229150343374409631212355950538456245100157119932605579453380956674389137715055744222414672178390929933133414235282743523445331894
Row 1644824236570551821728198137057573937781406136561742368825502403270014963143386726151118290223881805331633453767401257113224601283346555095287123155415021325444864559695483726221078220613624793
Row 1738274194215715042209407233653530127458845042930234246835288278053131793378233455646092514445724065800960516331434123429879024603104397341621351208510885655109777330006295656395453997303131
Row 183411504242035895304412625777217310682511752148756001222288544165248405714625968279512292343283733221172406468152542658361930141517370589648455384143931606431790346557941023184348623725607242
Row 193238415833303315552440327464029951641224117528522952574309040023565417720095719318312753362195001128175415604668274544142240388839301573484858742464602272227634420425250455008147543195182
Row 2027718431615187435137465390476532195565385143934898491743431644206124425061591515586544843676579652012392454480327593633404237914869518528112259185064312345493562730471914724791525156544561
Row 214741364612149843290240835025008293120121841596198420831311546923851407547230324710524826165952105646722168444156711549248447652969279657075371545646082155342424251898593118492791116729371602176
Row 2226183562138938115842439141819312542971256712014455565418851242104543748216160732731075738272316152728239614966642847267431742673560243919332813232032863312526513372743300235294576175706
Row 2353871402300239993456599423334794146219867530682897589813114804572226175068604461958173048160468537133932120265194935905584243837892643340322475862996202639474248566656645339279124631293590
Row 24580155962547324750266239832634491914025097546621277961222311313819589143482386539740582956258225253131064777427457586273715106728627289716993456367113335162152374655361908355127351286
Row 255453541947716614432594126646058224051226559347515464305253386230123326306515862129568349164431980629234895587570910733152639549929121184518938393476180150519925237131025117143137491
Row 262437528029851762568326181990132756174284924345313503885415729932079156823413482210620922096841491191468835035236246182819863243449613855602253945337057322593327334882301442448137484664423
Row 2751992658473159581729408248273949566020672937335283027361349268466347298037733873239445274234376040291508256425294796694397720814023146636983818103420542723900419125743582415259234454525474
Row 282801116296167443413087221320591114159310515911419524192263137314971431682418235242002469412624655635324914692163161739008742646561948565848203823244588117620374191227245922192488020221618268
Row 29120424105750274855830734150182319917212677603507159388431293992540519671913001534376011005948632321133846512691305147015654720163252243975972547653335743138515230547705588187749061341
Row 3010483658504645835549593651535536233012774199514846372129230722384472921232522011259435219913209151321975292168349047152952245896650882716268449052288487655193864164434451653129214913569565141
Row 318625454365330204062496953273759214454725068183145571599300849421123358239019254337200924422601550028731897235621235442289758181105559419175079111710622566541926931214150650191744642184256162865
Row 3293319002606378933525577466723883471516242638446952365399438028819084833350343224855921484743346224974284278545274739345743193509103550536437811994431413412983489836153728497759147052508
Row 3313832418460849861844463396550761694393937378817963543654539245197347947136198650963177362538057954004571785457354700195114931802864456129683521385549626292319418813184789270932905861
Row 341721283843464461452411713485576755873744652252721573684391642993494124519701094180435958003714191697256825542242102993393028308515270391249816142131949156643835603369229961284483028963016
Row 3540474605963434115583644222992738419556212683474407514181200240631411523360344765552343234424206110832254681528106949535917436051351030328565330302722503442393641493621755079390559883550
Row 369309198922332703318525031154524152691886472656043684580653933310237615721470502225554929751429442983630282531724968478145842810699799593522635695255840846124166223340414557468047835394283
Row 371185197119159373045239366923363449545975249575496401241221745025175346210464217840559619211871445226114743624450123101492368423285105562023192409308170815113118337480342491257306437331964
Row 384230137395458361005120558064434350389040988618063054234334353175510413475231893653502944767932989263116652802695532453729568263844448938130352498182011852873515828241832094477331081188
Row 39177823862371542444126463313657311423541852590722437841305150103419713892358145777025315447511753993422450435534427137863622299920373350107627122322341307362845271905485715523020296034931254
Row 40419744964074434326841144453256343572540455741952406127521191073459322683455325412621876702122387168512554481304052642782496045283480592944812066373756382549025180131611781971095505952712620
Row 41359935532070481016810003444538127148445042791553250715214151526371576116528725287576937015847033600349540091925265426933681907740564535283965439734173064513225633570413532822683232128171086
Row 422253403356640094645306517544698681272852853541718180723164733546259041099178650894602356047683035673519011142682381048714240697120711537143041420813832688157586243973842311735404821821
Row 43184153214462405140963538422414413893776495111775628304353271861358324213844448850123682565658192305646637213657103736094695357453993765028545181114292134544335105210589819871019377213753548
Row 4455573421109230941729563448203273464637552603270520143055573990724292231044922619837499180431696553234083483148244541649125346498881280443338283511350024665272690593211252077507015659
Row 456563573497213936882959549555263263331119413487564913104253415851577724429439716815292705174611306365159415722721067525949223064722289829822709365915292151336114625811412316813874583048943668
Row 46254831824303335913343052707210058431970475051292293370341862946215533884297806234448603199190146205489281633463508283636857242590590826764044101838584440201318085801283329383632333155042084151
Row 472735180398611252363254140966178674404644107330273599381227162613286692350915539732042690484266732072792708266245621906129590255091425132717469422947363915275932312902858436112745193
Row 481673193125126761951885958631164258299228977662248285116024537234232555833322033915686471757104877406240112632325289633444493427498460043481541384813616791543295528951537380019644782233
Row 4926785675495249953683921581431524827415758352008335915542546028609703374437449421739439484498010624091734386059451198548618219574776359027273608112855455291159116215124111165245023742340

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.