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 021075751157615095939344911461670494950412030350731676502561402093560001915118285221093095495716155455389367369512174774125238582792372439945083145756495285534938321129169142225045226338375148
Row 13241228127772797116266127423854220628855929427855043005290724159043072252160535776835034104849747292688344031831223502112143126435599943068351526554428933513212521845941232103581815852434
Row 26026315665112952894046401027963595519246332404305527162330445584948255048320963358814813570828222782310280184651772241582842764129123553474264429589265223834029577287458127345781
Row 31698308727555189255235515116554710351301514188587534741640253815305426573635423351569231052034491600569137354652256850692278191155954094415102013217567522555544914585252763388118540511767
Row 425593306232918695429247821705995509651338162216424111143734226418532438256959679811249021225060207919732221133428028811322157857481455401128743993283521238071314594015523029341233832524869
Row 544605802118337035376391811614518489817221689465341533001204537712332155636823795741383355812465791228347294892652280315294348209249886071422262431153405878554313533074695235695211233072110
Row 650415355346699759912564330143111229340451845424310517654254524475436377234853206110294386157849272548145247968465947394213102451200239445890191270510322199237228862764551912561590443052442228
Row 748123017347256833555968330259232843998468744823637429858025522369652405755439266746633744324745481042931210351664099515345174891430729262782329856014292322499713034769325122004736184938854942
Row 82963432940134218492740614402197142782796971346218627526313004208429713657138837081273585537583716486855281737516757565005243816652560520657462417901364459952273628369414455284415266055812605
Row 93684638300657124699976370236839593312727319419854457356129702775494738874385680344734533857459237709022723350290611195794353838605410317916982432235548382792390898324571266383976125211196
Row 103360429059022140463871027792250179635744017891277306065265985651362133254337462641854974744413039211503234011255069210136777734632238116974536623363175115005872459354924903151345972898
Row 115280169322364841547612413810264732533224499154272706480623104033374625465035256156835543157518518803093137218955927134411545008912572819565536367314612813791280524813452521942731811079693389
Row 12392147630938201003510694737745735237219938041777494865146337981643913281025951707146171727105576422322494579277264368648536224430382332081904797524138941455177658262434451017644818914
Row 132252212311612077924280289744943266537939974203297141883763476834993750435432012285733304281511831220599833284236394000120728964063273117638744680247698123961487215528226691499266117945558
Row 1411494145491524553306361742153201377726394388815388012035281542831504216158831133782558379140042921698293549032995282712631562327937336544236464410752548413254032554774256336815484140932183193
Row 156884935357368340425852845218516182348244339934810561821513029553223328897886629585809351923284493144516151145190439573014928762704129619661875403237245305564244739066082157175635873614
Row 16288949619515555819297538437904653450291111534736402328055885747613492949351423244180457458446030092180197150102036187032385699473817683229305578832384355189254702873390746646903935327
Row 1749783776551928841182810238026281521416453154908117842041299166160965081132552415524437055714406619363994396333961223441180323121177264757965909416126741452479377427624140453756153594861442
Row 182767587113638784340284551576673968580108757571256520337851095418995247184943844404800326734703653865928864136976514702453210212605533381739244047805820190140977209721228461348933631
Row 19427237533612158283601425316434724772179685237117183195638269318973759292039102857203314203883171642176933904212234227961411717685180594716311804546744311194293929715481165845051352159
Row 20317148082700730335230591072486445015268523421504840665654122740814346234398456181849101235321845304401353539812863316432817982144478826942594188438174243845844993424953041253180045721985
Row 2119553324477910461935590750585733526260221427238542963141532832429302741333936159356373990324542456393403851174561153371366396923809663725350618586517325139215123734241677572455431645
Row 22408323881408444533681025097129350221165339856441527192523303550146734185329105684058059965747586039759421132123385916741928590169616075277493853483931107394115965245557534742873061532961
Row 23535735783721284644278536585400498232393431390082657863809105411693210246121053317477825674487189356545832615461137658183364471026592431942791498937651699151187143411374252280520150621168
Row 2431565190151412244285436054082658328248502522794248514121997456730059474702113046326732964350734593711163727674303581436704499265516416365728230043732557159439565927983413134043722149129503574
Row 255819911409581454835042708765390828193382590689543105399518543111861577375216049415901246774824951430248441263568324742943761516237205795399721212536523593118622323695299956717823962
Row 263636456116171040191101822857835813448625372244178620802158317542661792510212045236132553684851277141452015792234014867337812396389183370335172923300029161690281739802691725102557922984
Row 2711882847584323823934272156157582215774629580211762569261183443605090118333226882876291220332393532065505447294402593810395757234636264525593312134676244247222446529339184478515092330842990
Row 287843269527738681420384952533141905490360213222643017327518435529243619201545351365341812421119382559325719407234674370211520333306389338708915329301736662393237917383378273547477044090
Row 29215645863106117034125260415250093245544830661048355659712303419183793523652234582564261071589231963693427970835955056402939102255428127648433129209913874535473149881868510637841238171813
Row 3030831114365218653024129397635614666356612672191585525859095163026117736515268693518334495179418651044683107552305553353935202550192056043264563956160048341523375155043408284547602056265279
Row 31203326881647316840401216553055883938478724651837557844521988291023682800197182832934133321243036948201179400944384364239122941271924338621742870329865354781478415359923182347136312657615925
Row 325005230125183540945439642834174521015032696781553625984194217338141347275211765045172620945287125034201699279024692065543139885065262497541538016641841786287537337271496315866593126201287
Row 334636272539673630150226724111516326827744664441785544424354986448016452589110655754056538016434678106046215872483211352525202163668447515348561112901355103563642993205551653012757116831372046
Row 345628564421319399932131322913273784537531315538375553161353452637681152380056315280146618704521648243866475632525989425744534986410314521541977323430744724331611352651389513135140193211491450
Row 35360825672237246932325733441497511217728284055336111594104045457019951912352031073628210624475019912801599487111095178477157315140138931662129524681228324425314250180658265120501112005437
Row 36330580422445767213349082510383518034560596644731536121128705869599917345258381187299821355494489217739554559231017065781414917702964263364426285564588748442069360147445964298139253465206137
Row 3750193263167855322190501831325063937323168029914985497373733239813172073499548153265258740797092100294448572041341233385411597211824750281129743829530013983413249634042246533513075148999887
Row 3858952821430550921367539736261371271426581551892874378348534051343248384676508013892206345533057852767176120525382460641784355611492012784841018551130125216510333242858102014971226512840364316
Row 39585249051882375395337823425564393028308365115495317093571305514588715773901440852965188916024563235320941552334421646801158261148532201386354110722714478336130158092571467255352761275
Row 4049174830612583581382557224961484157042224811581548595897423836522305240272056415030371385420034884082982424450147791124314143311679151019944154156212965646226616345794115097127954892323
Row 413526214338475005152736821287492616531785779154926993089222625642555322612573986468648956633582247201010114085162460950942572538010944988308659732032381932386525127481938011938575023821779
Row 421870573141594904475714143845414175892064457328034771665296226193361523724784073457118055267421354388553848439936065340259557395497509183746515668226943618293999166916335130512655739641851
Row 43844505120342050272245863131748131313043689231964611373832995858249534774658249120932634033433329145398530411605252637301226382678302422805940389612945366139866526255243269231368086695336
Row 4425295455565543750471566512969010284339199555621495092100237762402105951305423269876199632474432586613175314511989027312805284539565331538945305723317358569929185652510730721190118127673877
Row 4562452873097179643055574134043494980570940302422326696501035144713353618704489148724693540639105027884342340922235545813246251824268405043414772506534542383080158414627534932326546831243275
Row 464275842367430348557953713542833471944251415623452209248328222944510327743172111955832405134132649158141494166551380330829325063286856784459380434521735128634133148152419062025531358163989
Row 47356541063732235442473481241571227551763600329184412056002848115020222518331735903124309711565063194527352310244838202224579851175672464911621939575803239749114672338957725105406399056615239
Row 483027504830472144268526891702234289355731028431953093511356437411836421637329324212823264350134105254054191801411326961373559120319834831160739603065328153833762175532049381363399448393662866
Row 493332393124143957551130821608336153338433002323359283959315358554616715555417959612323251500551392582460646384398567914491539276735073812359446954135401418665414250454034159913618430742093326

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.