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 03103337239863147548675539903627350654223516553851763819359159651201865436828972407443139724065054317930641614250611491767221926512670219663903274357622953699149544522952576512018220062834
Row 122415571588992916345212501840116393776351840377115153690432028679981377247295051692618578318024980728141219733338407019384236253451937793325161427422948470144575391555717005603565732355284
Row 24689244501815815013561630215150055480469836343422212719671390122624500657112396154956781958128059352579120423302911002524418372153488419387439051237147681113225144342848517172044544692
Row 3546113884386181629256564889293920915517622449113515931558540479851498719461472527654217450125269031182467320248230431615589216223283403546140732272306245771565239717692337531959746355011
Row 49009792981325443855744162345301143231128640182641361398558966754612310277032974573478209256127050754283675514549935051333365336502123174729193789307131761994137955034186144375536583128
Row 54359218431472857522592227723661829325422024310249231964093402641104462458568725728264330292254253735578454312180598743834191350041815445345247041847159152548973054489434615339848352645804968
Row 652665265530590530645690464052945135424359137725452587437858721771554225924502416238328335515023213244544349728393146162934414023243552514510902657367524983095579322181867198429374178
Row 74084131268297445494105116712823812952459722856092243236338822589309630853998174514975243524255325841327110272419923573436815411248353470246423943519460352364025141166926885594151729181200
Row 85404152951111824480377138944204149538087291493462833981015354953440581471507290815585417331809150432416765036253145784254352931819856513392246728198320162368172511333954346843933124652
Row 95434364428294111461621014782204147452386152734257101457303431151543270434226774530428032973134393221391743952346349025581525317546974423002188824125519852381325311022839055836261330544146
Row 102097884358916293985900561720159933247540204332932545108565834285717331988629411797115655526495295311341971334147633987734624332954982136228617355446239457287744201112006161314053407418
Row 1155623647354511332676503956721112343765239774810425510183751297053885073002266423952183405120318628083279285374246084231277163046864389547722904733244146979302556442915342055275589851371318
Row 12543635011358240752232886426619713149434117955533378503841261594264948738312430513718250901986427449074918517837124346419212427374641425558723208236127853216558232951627108823441436244622062760
Row 1333791741082873176183659862512398418830549464340105938739773931813882252417681374507541882461196823095393387833602094519656387823511964264332830824920515937264349467120213830228739935201
Row 14543119865208199219905263544631033503415922773098193542125392451319619632252605596839914268578715894486450703505633468539187841852720301558232463772180739714997308123551544154958144891
Row 156373204171791351622024803584890416932654316453302192519205745133097450438055032661536422071424305036531227570449834806400849691373350412382290304057522447684233328019011540520724821700576
Row 16579618289231821148812261988234521834175134149493447392543063697561959397612678307037372838395938313509392394724199233011410169329014385967243251972187107137952754542639833647295784240095449
Row 174852171918301434357148192399218434992355873602364346652925950472835721565084451953575879418644275004413021324153246115343831772118019102810427630322436383649553940843330487043411916573149
Row 184207297111711861417320321357442441435646416349703874150550382924485224403562543668957768664721238748581434468615362720595846112373360717873407391521213293227254612497377948252091477326216964355
Row 193357569636885434223274032403838795246530881533421553945026299555137241080961988417755912714128954045063261690260765342646491978497176315512425232945902434514422622376937921224734382
Row 2044342430515654664319285422761804366249724269549422825518417833585943580357333354353814986245354054380797155620675846564350834815353870627382411324378220036384500520641802212921519919141099
Row 21239557791453349030924380826236917035811418844192791235055022440252916958746945482143158463532642527219497394825534842753022185465596350073734190011961492125919142332190617295560308927152121
Row 225211941237502839791941673216739915186292829922375576437675110590547563024473432012028111817085941480180829192020381218502621484152042998217272019672390447513962523229758505960427632891395
Row 23300353483305334962204918085416215333852791122727603062470055243807240110095847587852632140323393939363073547220523264247752304457560157941355539244323331396919882740451026954326541564449804770
Row 2441745521236181946421133307235163887344236662735531615145998472359650318063400314115411675311940818658634141485184619254461612574723253530153671850354864506240474654356154285829138759415508
Row 255283432462833591151323116751526247545119056285541516127613471843870565473826043971351741661415262430583211067278947282050241522795013147442244484412536974266418659363862330846482417092648
Row 26511622306603865497633335804158811481746347431884223524453594216250320161038474458721319280980306530105232112826393272296857649964736577052071015360348153901076152628602477501639715985282
Row 271882470324057198420333525294648913944353133872293518638054689250334655095160132412232564423385755036952112340833334096339958824725972327154032552516474568311704754389846645353324852044824
Row 281545342639974917342440954505463885320261292101410852788883242720585157033941100327911334279869040458243462438930133052588330363210375802540113433727319195824569250804283551587934701647
Row 293975124343532960293733154147328341650835272106458744735469824282323138651562064336623464667448340044141445418156574873366637183342328949359917833815369818434342775369478756173472158658165008
Row 303885442929481166206618151298104216437332729469757873048402786723161066185355741345380336579093392588936792187411736432289111757183626123630975498238734592123591426673228312356685058403855384019
Row 311479425452739117639023466591847612302337111051231304923062739249331234822540248214911886484524355797238621742641184510085237445313584524457339081418297020013289425743626693050597313331371920
Row 32231919177146272276445127351225502486011335252594671221255569287253145415363331302230478658931539955064768327119162881202438522460820603633225854521593961156207240673431135744230892
Row 334525009202334104600586929888665577477553105642360963126633597227954462182644953155445903452189110904423888905176439432464956579179321241652535596048474703381829873868341148571943654557
Row 3433843812588827102843413551694159385616383778353855373860323421127408325482781561680420871336537123375517329821661177491323834317560636384943318346021061579362847403348138123402641394514683836
Row 354457731417342773533366228303083239911576239292988298216519702027107123651766340070027415907514245243960263335281533307429961228358561645831868256324544677568639942033572425023869971830
Row 362313348243251053386258752367541187529683583369948831109583011974539269183050132383802391397236452045826805252155773198289716369537671453151866545205775150051773224243141031818343938193707
Row 3737926612223200435461218912177604709301755142485570471848983882548317963513349441532989408225272900217915924532109222917143117407454251003966437929864297208958835538134358073289434543962935
Row 3830593475574721782353327326934693582216197665410207523744977150120311294537847345158211237905895888100492317723840401622622538443373127642061356652391753473721084117482451447535351169049021961
Row 3949091291139530675325255853531591342058429455445450410209662992147536763975148434343501493682732594793325439939102753303850258825131818362534041777139825352732444498437395247226353432084381
Row 406165772513237702502376330325344309364143464937169146657353519282762822394055397584554863991690190928463522617121132211729389462038727705168189253835331566353723231418236362194561443375579
Row 414002458616539993817225411994813495241975348438945115308455030275687202527541128841461463213493162481837851336551531342610433255118543970497649245132285121362713123736689359501422371542204959
Row 42319711452225232722445725505623541972215441102867527937741401154223463414161013425055342047404845577347971122236815832325524632242533594304531415342063552436374625921403649784309424886039121169
Row 439551246128615525816227228847544818573478237294980409155152377121128743401111433085254603833220335891316454512715646589575744461046441873427958712579570030881850139611854206580311542931856
Row 441723459527075694531281119119295835522535597226023275000266123801592175173133584388233835107044745040395728734353183917701020309027562418302316422295666288230415213467232051273538458212631
Row 45492651373196378692989166818284562326942413732210337060517294816335958454513257847340669618831105267867298448562128333942032493906528136415595370256162703575455044561613089348755643335
Row 462625065719324030432685454187311073168346353601267400947930631422117092131011953370214375686373918584561278637402559456025635449144158714343840416910102487233337769545221245745492645315593
Row 47305220581388930420013703479344453262341293433853750599210814714252317722305814567048431493117418711747118236405179221840805124624319591746285227205872118085140694145306469818865325742427
Row 4818683113433794278020551609502584256845413323812919158201445367711725030552373922765924134604286631151869384130542616303331474501255253015232882222214344949223750464493577657442920344493
Row 4970627222476706575389135385990103123035767268953153091114250995982113230375925329446869939437444555354850551665135270130132842301139565122722132030131520485818122382118236114717292522085631

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.