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 05953155312213990571356573023456624602509267242663618265213911392281939581395478055162424195461255071516332727152453214759432495555015304748951176115795534747430232672863477380529648804354
Row 1726328147785492530614714383008266441113814172397343431792282166020112169243739121973772405318536053375251258042284378647895475420126581988459648582938268619946974654307256175516242937633
Row 2504293430284790391970310129105424324421031844748507144845801142741642933277331433435593444727257826273820491225151677109834845216284522833833279212443314942250805561546165395125610925044
Row 31211548521452222585252965126443048283048574837431825215718872872977328161452816915835261413135341444636822654187859649223727114228312503509636863524295713053410167018892870381018891928443780
Row 4395444023241886305334295125402537155787186626744291759684278323182201664298259921696289158871317997368411711542246257947942007237754852134287045734431894369024264339216547013856348413241493
Row 535964585555147578737047241624355701634257126571544883465940182864105820402132150136803188169936317962208498749702724126758074676569433222173448513457210783528588551928611537161244656000
Row 6568969312755413163552984302330313383949347357403858538342817565538382782094449447152808140244144841215496636942362324685855295935843216412923138037116597781321354588492329229193372
Row 7417149102866312613993563196313671477456837105481245318488095118192654288833870463144033792211956993547210926875954551438435150498544817226144738131538901494131771438393633631180505231413663
Row 8352554042762208745548110811136525426367212161746418320732223644942620270349452553715280383611725401266236051612534297634882193502320916253187219239951614406115125268378696818502045111
Row 92998191137243904788433733762018286123864524206912101593559612414452986514435027961731238010801478509224581080947591296825493210329938062733364990910731505126517441504156551281664257628835884
Row 102858455147521625583380447334207201330451278165138864430704273198186924344602312357311121490528772472121283017673988493856369332719524646653683109596111912894882920582920742568473133895868
Row 112205385845512689407414795378235242901754386773824361151217152939565493405746281938630275046924546172422335121201719435971594823924857356611073462366472312325364217163176544403292299647905577
Row 12731240242365194419443821285190341674089454119224778432925123150538425493739305833112026245816945720324527653314142519027835947176010049502775488358065884039485794263440225052550474144603557
Row 1319522555144338073305867223551635149286941262722556649683202557727885297558949613790525642582683572955323803306158394405773151632871706394333895546398959855210267920994072136047072365290741854502
Row 149027763470595912004801264727314734257732392875450718963009574129754833368424586292340340749511002582736452435113557216353883248317012548419233414515260023679073859125316784158125020935653130
Row 1536502425336036573741374433127085114508412743092473310591125577455081691420731731615504066760003893122313832651864126547591724360327974610263436965173144194226947052819229653411671836364684
Row 164267318142414261371025343756362575459795081851133225581973144824732221231111761479272030083083766580012215953879151654174222256355364012433041940120528571074337235061661011290621522583743
Row 17310374727153700201316168203387310314673818399267593434361250355939891048312671645643779257445591880438023324495411457772774376330472218427013124535184622425128853101590628342273611754071
Row 18279253993665169389734524615200856141386562842791047592834273598351810292851309838235025594323244066372915604591406524752796137476541585179888115680372126703238172594345272590305741410283806
Row 192024615406856185159171454793245160353761314081923567021321075178444343174445148389724599851111428748443799938120232514831150800132837758205790859269414463363895507247554782159626061810
Row 20487737075273910455258993416477251837192224510621551129227115831342296303842162634514280460142911249244559134824898436241621862421338213470374833370929734348203668011583826167049292471
Row 2138133102908115331232533159425644915309854512076125341123922352205554873827104374456231038227233104794674381148424946245332675159231714885483332832922711297238284367176350423389151036152435413
Row 2232084095754243223741912471470559439461598484412302799494050802191268538721846281460170849831054338188564147635582478256633890980165046403332366493832634061179890211272040121583792675
Row 231236243727321810174040913426127638983515430129034858169827321308520161921885725552877311922185329037272810266577337253357380380151143230444753143693381557221013895910170059791043138741941124
Row 24501144412468663287101023692579339338732307343350513509890329245762667167923755848906359244814445431887626733680455348223013663232615185166867468350556204059500366836411945481139052270576
Row 2554293718459659124778421755901471306143082354442858207304341493927418504049258922092785826478357991491255327105806323448441348646382534941581483338841233920179339532126474532065556474412502547
Row 2643850031791170646212439435832201676338587111782046530835594584533622524834454952814585157621624365540865271234752994956173813303779473458635395107121334471549264238550875040269441721061
Row 274562511121213284351489027754191245528501393801436056893933388322123166148505049672480322949819484399574322074302282152552146218792032262465287112206537824753452911274177947473822302536
Row 285538794199826221475440214562060433453561096663314421532068857454235273800353462954103050166642251028238751932239250635624735552524290369538599363562807141322021712868863398450515153914
Row 29532559512180378058573735315361011837857121975253585835099003406217933475299269812322983798249611704770418926855815550585644236813480480037824834450551525195293574433614024540213071034221
Row 30126611004622169214517585100536238623025326443921011785209052522004918153858763727398849992899884313231495857368145343131448211244059013199184731624636135274793467235129393092228423321656
Row 3143075077999346331002965240168227751904013396033627934037143463342527113670127746993363165930201023305317241192829400053709444692528450388321522504552695811832211581836290020013671313
Row 3232942017300268912025262378232394364390439824566294127056093732616214945442253214234453321554303347463353846497024472046748543357985146187553165828333715154874182851353220150092296249295157
Row 33205517847092805232577578532665664245554227474612961335543041241155843573014885790419758522085477813284603109618075619171266741914640311024525231307895208897245171756321232286904284281
Row 3460441873924682314230791481221094871537923127232835169148231777507773719020864424583821053315192634795073394219025521473516122353464424205244869075535263557608395822759567542955337481
Row 35582856853941869341754761032290920674156144410031150274959325255862461557872530397055241391239553631588417495342377726099084677470421302288305447817591391495454146923779764944187627152235
Row 36390358181193668180256841581234352628794065401509262549991989181580910340444236712733583394140844610161416654662418442384641361213354214262451219055275331384451726852811195419033775411
Row 37202133032092452056594759286296033415489402728173738779996254250544561298366289463027874962527416222039129424055922519943853781309655092985645908591632435176143146442988911767171937095036
Row 38385941795479543057104870347958255317603517523123583187233332428292313602730588716112950167956812739255145361942579029644173444257182629532673936791902602403211123731258457455332666516934534753
Row 395677545374823993517553640535085770618045232483023024184593939341313345007421441975350509235328489014547267553374031382134843575733121716892667459524212795667385607258649119663154
Row 404081454426511470519228373974118258732331300318333298224593334213023052591320485787252237789353311111470135024591879491731681477106274952321796248650534707118942965349446056802603484932431265
Row 4158123467401233353821185857774099294914383340823470452131913981665454034732066527817541081937260322034845240015921269434732751316520580458691907501544334598326128676862417362367048779074876
Row 4245255595379619221361267624034190216092626974276506224859543605666111725782917184133001079209615785656181928764335566959403228357641941253168711198704131255731421396929319224065535523124694389
Row 43212596111564042477468852082388359849433432495252313061061139427462612429053263336303749843632105051055766774465022572441434449532216356242022853363658663981686903230151349771411133036495886
Row 443837477519454035312527341146377563358496131523135620375680240893621241354564676178651531034519957021634519229133101194025233567389757502233289049262453585155563048364747815632513649649211352
Row 45493426753457119444451181955244711943133225041582155053100575631451211251543225093511211232721253223736415317226335515882211418557701072164645271064242815291964458923754444728516121625131885
Row 46189123441880431534661096476245152154378357362813504665530652194548450757841513320847515937479438722024894175112923192806369828793432542011122267130614221265106435841886539731444242285822361083
Row 474019196316003252443519796765194232454741450408036003768477228603333100633013342696411058112293907939383043595054198348552861440789353936347444856505247557532774144336495552913389145923414
Row 48528345794588499262632612817401523405758190024709587525007252435715042207635075118477057302922101142824303214835440257194797259321921461287731213759508933962759182541461466636262956812514
Row 49356341433204311531461295296914601277194312440313743853198104694827043018527726231670231852975424927595329042374710423844141312489260612023301464118195951161023991161434016775036538132635185

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.