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 0440940441676330050775663368445782128202256135952734442465349031499555112834691572619895307469649614813245723785544927244323612243342145751311217055286503915221972240446246764594346220582399
Row 1421743502734234151964814662283819765423289354042281180343413478180730557584875628434564424153524215343693575334136082856111228741925685299248316333647544432523962528798922082398242
Row 246753800175339234932151841931857443531405795306216629269734052660563625192973749813566422982228458031448666922853543543054474588346492716101443716564809201670120712821170444705268274867
Row 3514054711322523447333376377950832435362700470436712235431543615699460178844620863869573125856465953385072692441182359061061358053315141466321248578725026557251518875788900240310855703
Row 4214934503488482261229071333570117933819762244343439952222965460512534241781187181678259674032503966133612161436133181084520436323294774457253437354121755536515872234502255343511003606
Row 55251150459310994126432213594856761280428485082384813974539236433373539200745391489503030443345245434155281155339620245570159044402349165123240871195339157735364817203628532083524427941642560
Row 663177345085327852905767511541971007284949161586243010221774334658093257503957171601461853250020472949160162557431126543339214592514374747674729457197948904824506553451623271325430614396
Row 7431521959552611202111595012533525184346113045482649568044591053187581519954132205532316334885432130044284272395335799002758564952842872921902550503842501444714307508544185356150234472825
Row 834881086108358603108282226608181442514448721141509160946878621915309521186350840323634504584339414932556123004324553345876457591468525738247944972246350833320168744789041344375352385380
Row 925802777128255372018285643244114837243132623464150452821172982846418155423982308327041477506832814150391621099541572720397622161564230037607582073147045549262252556119956623138287052744433
Row 10393144483305458942618944752372634024235567056812579523043298063015105227213983912351537693774340950684020792386837161460886458427294007209158304547854518752023962258421212754004150656203938
Row 11544817831521587014711862532583445241239783304522704977130945211030311422191779174851102771572158967716415819042582367650373672393498414275633558543221411403867313617951784361310946615269
Row 12439828801409507111655396273545422032343232283249531654841209225565040844348590243903661774404638442686586692938781432377724035518448014335384249959731583508048845136374778577285722313194147
Row 1340854355352712623538161265602423813622242773896328525239044140569720082755945580940333822546865292814253168637135947094431253312685934389144029424895261218252601053443334474655464592
Row 148936174111588640478513735835368462124214239119313946871192736406237022679346357732591735249359812120386025041860116244648952504273563592726542273597658402446370468216873102586355223934
Row 15154457859014895539013012857566315753123101711893052299212358811397551616482908404852513326544528331839102096476298711262636533720005316261431411719215922172354499812605102868437940405151
Row 16477720435697210794793538111497366761932432685596133644878478257041272540150791152408017961297206230343103121402412186125338587129517454126453585485627833139711167397514992318535530544180
Row 17421821114566380642483780187253683722773565350111335031446537166031116159122649792138102647193484325340382748277740432854794165950387690548750614173426814795148458043454265143633528724148
Row 1877545623221412135814772406347315345910546928282922209058412659754900563653824245552040088861681348646511901287145831466606577763754544539232024169337494841353965309729474148324917181875
Row 197893981365348667522332122743832275574378435915050174206259201215176437185539332623002086351631382777392282115111953903418151141014095289516814185484174255602319268334621195305858045696
Row 20482252429004962526347511292122946053109537854164291620497449065249187132232060345542025229142757163651351396719564715146235934165487437642753589186732781184551049725945560230351533202539413034
Row 21765395133122826554159511433504628583039582339122654668443050322541582401619893037943148456303433741310242515251887102618253672232083716395409180731695963775179286137055099408222634452180
Row 224769409137553806313423613442957548059923751841441335391999251460756244612260116811021644152410962688462813523402410622212312287846514363561011326912415700578750261845231430612082328141722635
Row 2342741957180715503104155286435398941547112980318719291299267830934724804906184912223109537122812746124532074162177713181641895409545541085440229893679462242023897240219875263389266454312571
Row 2448222303461112031299521445132986441016125876523326922568202662241513600599842253025148716934978464019903241512922532043239930326025113108564141600064330541091928292456304645559739899543607
Row 25619409193524256441305143518671135535327132191535023703510039574753292243512902422447634063211157954048704476541632116932933126229814462393307739901560674217845721675259941464865
Row 2656495073314542714999302297573620704642553539853882614134130111992080461027138931032180814559871422359319012153544916509219864091393430242899291521227756012903593371537655155360439411131
Row 2732652522644208627531018190734535728412952871812560620725769384850785218379136447424992122535894615180518719615653121147736736314058192132134962419259603674321196564617743357487052431804754
Row 281465565539103228594017341533258575241042025221211382714382748632222448723781355515623525680378953823380450833624940143629802880555454083921447023035866422657644340408237453287394490015277392337
Row 294873107916172976228319358441204572436465474406221702588344833385111214617305721083782382633201325436822523679455729543140536284746355959524091438352865117341558255167157252514593386956783334
Row 301221297750422058246356781752426716863431253942124086275611311618157263942143482218115042148123191381325146535752181539755446747447555392887155656582089578771407449927895380396725904203855
Row 3112047153008586225751425883763408954354293154543858312527526313373052871276522950922124215456591183421292547365767925802306194218233369416811794075212202010205534586259223050300047484137
Row 3265554954197198652671890280946943554383183204337644996280341893997104932814984527447901018375636319773409138595053266453812640400100448343344487343325816188928331695496848271146449753442
Row 332234129277742604591337443311980296748822733599713925681491237184696313155012314139221421934521944175172438534825767144056013229248430614403494153895765433350442393461799538124694056138045512079
Row 3461950474175361284010162612892411390811026722905168182237125128513315335542160430823334710204350192432311505373997038553076386717571355307111645944121411289138313243757144366044993672
Row 354097361697945991343374338873657428097016993839432248379653076542457547338381037463522355015371880542721794582141256884839721251261736345770246398848961609524121728246742674307947621769
Row 36196739622999301494480745838951612157447934536600500916545475523441373314752347841084958470024814986689577636695897421933135289354332333018549810764790771530724033118462924403744128724912635
Row 3731823229564928152703121152615311364156536335639935032739244527962856172525845200276054204903492558565991526221092951725581029257832211267347928974301967363231893165257947921121570959883191
Row 38462022384000426179750556661004167686122632212590726153004505628523304419311433637472808142294055312813153985010304616493526663169342844042127134840533216138715888238551534273254
Row 393218419025937075681225377042544187233815571660905112357044943706604455424451122411190522215381310342765602508832384498226751695329163759325658873949359753911429035526474724340725533424
Row 40364259193610206235921876393319202154573851632362417404082149250513631016302287520673237163625483659526844163116129803752855232355238255775127189219875323159634945427368627353137853561
Row 415780827286611071487249112726734764775593122491511190227093241172422825709276759912503679455523735241868340749914854339836121310264357291686479353872925179336315124476954801370422710732963939
Row 423968105459632764034328254115237353811159342611185471036603610177339713482206221585882330725415843595256650647903489150131047341591964147395614301763256244114661934166623561449590450915926
Row 43229325314772443463524427744851905129258865949199658984923176558130231291423633055781516264458197726603034862339565051527644242985169960759755341171034572729204031161701416081542391077
Row 441786203333212116496742049043115435722903853417050843392569146454454548841905232940142029213381230718791626551527412824796178435975871449827761665670590114851319631868449059911715430528585620
Row 4529403301526639074434580458948031266117655755722298204316231813992374818452898514917634890318117412362696269413723713256429061715324264816443497117353184154858284975362412613782816772369
Row 46569759785534260515544413268528765123359636315241975163618301743410575184158501940311898624451489372348723478288914524051573658354242434092256310062512331213635911497657723792320336912285088
Row 475118811313475027432620112950033397418358711603152110320164322258125211154342524247065625356124371635128054491324333611342316044058577320557419948081830539013893178190014952443168236464010
Row 484309302934812838231641203827343223515852536844254161252927533043942581645981455255050741928183636839054494560190916943130128131341863302151134171941484885123836441341643261550463720054796
Row 4931015265402289941584439386256223770314648613414626595820914407051643674266244964466542400759805866569094325354363168139455625502331715615723117554413923129455242132598136414639418511453139

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.