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 0564417867631356411789453802463488954642852271910254970564359032413391283284848034171508898450758765375511669240121184465355891217407845111058267720013081103307759261604444416607814361148
Row 12382198826992060107229203566376045196249194355061699133629675445488641584320995349853232542198830981022348135792127399176382747123005153114441853913044524373464352615145560417647764828
Row 220444295976491523634971727462536215893593792259304762311942616487793161449747843294217655191464294629942784656266414891116215955764645455569736434649228620339145865107762556142639402232
Row 32083145457571039275829691531463827431653444351893200268524649714017310550585125263182154858253557754415265342616013698334747588120892753934206211253438105813793844585429622794475351393141
Row 4456233303074367149742539228336552882549537210523418476025924708529249762641243911591215138224245291487530779021732740733356329153082589514518315041359138734595170031579933178582052934830423
Row 5257936663714012028406178322823454512017233681687460326222927062601408859274457562235181961535694355590137092076289855501889279649562544221232622165241621852545231386518593999289325753493
Row 6218295427941455285448184841568525332365753824434858540834547171098239010034447281125534783594324925406322491335625445513614295361419238312384909447526995785416140521421205904262048673709
Row 738058932425448154428733094255165636275036150936102400138937003436282137292061471034964952672493479215482781344639503705363145815708212668813372542897457658625425594492162551936014245
Row 8184439402646190765313471602411119114074383117236761720197258716922992432213262602309949183740131112301917291140691289518265655314930769875518564641793060597190341744553845160347747444172
Row 91520595717947544613154410546375738307617564686481021225742568536455644621005331134724193131264020572521457621392706168526874682515352945353802100953953702430947213595394021675305339129243959
Row 1054744494296292816184968427173332641663156841782133297449791872168916205849332141535824491005307118520547594307260372517247373705668229156991358873258445055080364113532126402331202441
Row 113207406556461940340952017671364520127619631123389617871291244560630410129751115429329053205683292233170451096905208256516068833469261552933431382115234223367297949285641493718763926386
Row 1211601770121654514438361210185110242223011331343034893105512965817802889359138824892415119145952235741812673443312761025198419216154878116122065835362424475777387737915860172926251658222448952851
Row 1374545614855572414318625922541554037065525465028241291154903307754401591599229246003785456857654062167638430939934035792009274433823556514245536631661291447355669358925545459170254902974
Row 14308440417709472007053274711583415032086062154941517459547911233505361121614193975128231222895261129824061217153847044061252213862323441135151979847318237194834182139682540152233862629
Row 1538531888391124179055618544311143719339124374797419364530334069593272739293982121012493174267544633683177489241951305531028202354139432755163500377441134476212196569554575237404563160734
Row 1692152242886320123514945588303216413877581458365448450831641104302234965124293114563023116354530104610514326517671150304032532293296040702630253947355626331060003015493139926863336160818125807
Row 173361833168729132163420220742486246931344714527219225422752216960483585234191843405055224487566854504549472119992708279612301377183026895367340117475076428849244735552917856675097467542284006
Row 18100352881537219410891686334836124404192538511634101843893412209856212795310032063576322517505599221336392726157259333337141909328746621226573941732732523282335575433197442024859799448339891439
Row 193822417542104243815928351219874029438224755689136360044015288551712915323197584848428185688376644923818222514826735441286457591110480975359346813488424828763975101591621674806164427303081
Row 20573526574340536437014210103082396738531820221878139024772187268731534495392422173517894435313638057732119414622781752943135448143953013229264439992299346641001484204033332879983594643
Row 215964352435461279838492391128644084263152914795414347839775196365341665927268027345433541333385408971266115032257355049021215551299438001345343490373329435816753570520125083657574753621635
Row 2240042915439382612605392308949123371895487615585247463830712332448052185544527828923843840423319291704464212553613426554713170026571757319122115579466281934153515284248624328289658065636
Row 235012501516734557513757245117398351795015347751354434177471114822735695401659826685408303447902981246453823068250143144819237253263634351156762849460439524956489426112891767412247838902892432
Row 24389033478645214252094154985241897034943710236371653691807434753731415302239748024646502640023433403077303938444775456444833034277890055017914767289157522831275329428820677014282798
Row 2551229522000203569044921650533516051604243135341871300112653275219656569234301168291340682443117207342672207270341046222225577434258993140681267531363373162174213152581366439391580471605
Row 268558712562323951752039365270825709581032299720062564677583350834113255910253196588064128895734156238355178396549474915268014399123432243156842053226248017554015359248722022324023760227
Row 2753963348113122253199108939605759469025544207458838594133350541973231323348618259711252305729362677211156214107460564358478491925562122424972504413212163608191323014689208521982086244636344423
Row 283143171228851499843457861823261364864508731704114419816142123062744999205526066673001985230237003072522419271184361134429774813532310192844942165333558604959354435026853409464929103087
Row 2940908322407164338902738533314571617113859098225182139398130871182456510323664232334451614150276398059783048422138834583544249541349213843453655197855531394312848911824481250782863232012803731
Row 3037982237203225824640144935574256320211315395326551084957518928453332751421320634814229918152390248024784991342614373992551139625951564541656404172164049974945273245474442276646381753360424435707
Row 313039443951914712556546185451151497186247732866598627844063167138462052495585723605567411252035242846324658814441721252848981745110248213216015046135445421903890323926121370345835233253763
Row 328626001567487747352887291039577626902598325953394540224043372710591727662275186216741076164326932261150393528295210498957155139127538015808383247574787131659892729455022213381130147757803359
Row 33518418350421969343042234151539718751465256657815209229455324524587279793328007652079387231774238319412531694460733153681204012833877182049554882163119664761332798725673720503829853274409
Row 34465045834419658773296740379884955595733033111543930505395275027241605430012001395400524283372314135524232121054184919631279531265223458071533407737464771570464618661859447324924949416886
Row 3516634449519468845693943388847602931453095299464073851245433940125449914349849449227598724848486057765628209654683723279749345164120759862562316399337946702643465319442000357448753274352
Row 36192230722940379027534808480614914204200468337934598523044995700365059403566325747473887219521311432152595053423943353826662069749373835223502028549029365819524442961935466815042491200637431361
Row 375884522738033798478487138863453411438335468447414354696417446311614191525147001327532156116230645212965522313559266515996367041023979399621904524293150815802195632046420551635195643652987
Row 38798428558824859451648654200335125953143476916144341268446785589352935205657320817701628463847457261760285387216224668149186109126355327422727274918299323333634344959663880765165116344573864
Row 39549894248912634882489989448804581140829345965852599212034114294742819391835340434015987219513004262939835112699157724563724514457152642398824604071157155044944491610212199230949733924
Row 4030946392581332252108651922245515653869532630641515308333932238264546892588366215432060273151676453530158216895978276943553988588599924991319312228345344289843038449993526723005269215223350
Row 41235230653812237413194241569119552825953458444034212001582135314455120019065516552116382310129012974618438641812468276113673730593502140181720305146871325126116654867094554333759665524696554
Row 4225723047271047785577186211682921469215804555334637942174224926904675255358355930193516161249443833293082520626243721261350151223216184559471989448231255301374014445268479832003661373552716434240
Row 4317574740352128744517442838282549199945784266288126534118333500038033365207158673623136938615496912164426473349126849634879584150875258337692503233073743182656093348204614757725283001748235
Row 441557339250965164193715539605087188813264233858126438211092376540502524586816699564064418623550935337564635363596749951899187227732681450452882517546591533912473514520918721041373627334832
Row 455694473250451453321637436914269539716815449599173624965137557423211669764543628394492393931325753566371616023129326296727152200236409935362047505434974215124321024569360686355704513763946
Row 46226950365084271723306412471299751541949273827145551539523336185613203240215102434282239123994694308754662091473018143105477554095304319455093081300434383685790349112917571164174206132645227
Row 473444302818035594148447271817326634955171626451811603252831345483267216516833545533046573921459159624323265139129403064394333547771762187324455204536831316136331847573897162421442450
Row 4832664362154059094205156625718794205143825893223038521519457354542351250622611191109512785179307450765388177010904811292633085171453655652099225048349531021314829764197463133644511343730665698
Row 495254112116914285408292219152194829467453926724572598487923903876158453722210376210514805996236739175635321415252795291536901116208655614784905393833544422296136653585172125402014182151501603

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.