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 04856187320444286225510243804976557089826763474415841623604345459113451202239991049284058831708644273328950155034539745204921439430044992987375353056334102295542595307348247023922327519433623
Row 15694425366840422963555431675897100136703149252740283249361739425523112113528162659924944902304650331024656558141393347894902206146926515302249126434074184254122363477746834275322025262178
Row 25467197933957935499922455060599827221826397846368761612221426444453903785446744765683161527435862244943951513846537651383296223219661426114536251065395327031668399248504733931541654311485
Row 3441401545004201141472557314985540148063964350050124225309835255710407544722249835561526026681795596513274425133761035413612205199088758672835349026764983449919073354139325044607479915812064
Row 4228652195641066360441198756852623108279843761602461844784458349240992576434628384555405213464403386356920935891473746805580490736767141127480520378025723397111891992484033117525425995729
Row 550665227544497263611305683518679859810005108385426323333446442608963194181536879184129403433762590177617986013306129013272679184650848514763489160111805847519238681435210251331643574752
Row 655754869129732653663761927315313791251662474631491881536148999665479485454442760123951884992322111454812320568914713475580637611972936334821241924441696409630245915413044814118314250323482
Row 72737453633565059112056313397204348418150324262526126474720735503425448173357397182885482944914585297152406157245783471173209850675718462516304125244282245668863359754376433671191
Row 838002704238814873756644463806442018216207585524936134955272632534469447813885224191128843435524273949367738523375445847593691443145201547473449353417286820964335198255363775331939754643
Row 9197376279552559675747162744232566449317813645578394249705958355655622933231657484900290831504415415442661033401618244103235564448320852419544453921002476356541517402381957655180171443911540
Row 1018094808285055741063196168732392843588421262586593724189333542803435451264215384814741558134699186727002298592447955375237059264590250956393011165414211123151269137835903603199629855097442
Row 115366126051891683331213634063293519744878449117331194188019271702984885597812091222231194120045374549512432434280175517805276404023597428118072113764221312142314509314333867581284736103304
Row 12369521083375404284339514891301188397347561426295748913573396247424799554471516741832507239454422475261967582827514180434957843099220572946454766503141484544293266269135394382420010393701
Row 1382652558873237394311302839277641015922067521069532642473357119771410381612530188473013022930197812763791842433315651223566275946403121420402010975850344829953314119053133382280134211182
Row 1424263662123052735214871042389328250424141783246558541223305431531225699553287254947673564205461154340883568130251332238265886024094211337054832064276954634527562755721215120433002755986
Row 152528149714305260515651654293633577551558171224883306015192557765484581221162435311418575293593930510501993552744464279321056811486192540675618535717513879282342228873152926363134539444176
Row 165315445141192224613231654144715229489804556421087875858251330253119085155314014428336914371772388654948442842330818151115305215166458175892352555707351497361554924635330596538532422
Row 17274127722613128624876285808334029403948356628144944108519101795384148811581941294436724176369033981801401317510132585650382231395053430232694852352822595761582129325314145737123016631017560
Row 182023386925553070406522253122595910404987590029455706244053415092482535161064508932593897572359313549379341728097773946211715295310313958845975277137242204162578835203648593025475950145110
Row 19264329663352456153732192452359517622849131914961193475253181006962762151250081399483757640182558110426437443358838373878645603039184243937222724428947914327473096768147053595462552222755
Row 20753133743697384555467130273284429644977613412760241213081917101129245065925497337631844409154055163334031012607241929542962428345343594134466497629151812892249634842179712108724423410547
Row 212373602400149954685554214812150302119584740133135171644906272160479850106192154372951195154582192349744984480442585441534245985449562957927841412193918136520233301409136315826580510292673
Row 22437113861026474253961765307222741207415417268638253970276813391530203518741341824598219533854789274476717151077540541846673055332562236138104094472420136353770459582116064777282655481784
Row 2350282580201558604383722400458392998126932991496518238837183985358276023061697435285619553753491042585146975093366256167256595051256929372454463288858737583412416206823153308121025521064
Row 2424612962097274933095226407744702801135541882451293989393518747203740390847273638455334526564187825753280747284520101782325834131577624005836925166526823074501429664723180208349875733295
Row 2515495255876507910994907398943133240194249521503445413217692049485642933453168336982090344229181091448318503723442911914263343631023285554923503060472424785873126154394899250658743382345818333750
Row 2676145854597121415109802337141434931933478414018533401378012095008240246513741430328353767730324341834678126120013840249732321001560433147892636421334728132512234857775858453720324076943900
Row 274739477558504703479417354349536739319883717298434248405756303264722723252809160248653332722711622312041494905507844355422589411759741731169230055446456519034604158544644844895200239122163
Row 2837482673200516594071231729255147684467318079950285532355633735442459325164761500648650014753196016712745776405112551467161740846131987492618683502231425683791553549913654350586082148573352
Row 294040127051901722154472926362712732550619931563575438467046084509335634223639379115862963170439762285479147041735132479029702502527721901650554615085105467922643360527336155260533538626994530
Row 304724429945764461347955933738585422995236197152735664546133203429371237511149674683658404215945629545556103499513459519054383106555030692786392929218223495653153793615184863215234436315359
Row 314963593812271646220246751793236541415531311465211485358326643673495165137662294229428827983957278549639182333593931534371138516115351399528635970486053514404488734415354176133225389376946002777
Row 3248981846273289721195196589929192381679476029003696573218651235504556374897984313830805349430756151565208913345435402856284871309720805827468864560621671726562345255489322631631171452427692675
Row 33153826495566420237863201923390241349851081487049535195311447533739581830378692248597251614835509428455291160176832164328465055705378557159963676389633951796499542123307270242912521136336431193
Row 3426182014169440024116235253685346438237932067268622522085332022625665231548892351161346943837259345671283361631002918582491410032568168625481049105928295785478695125311851942277733336093210
Row 357384938447516995699046446145372127256355863440439942503071347635954948161131505435379985944075515110321284311563840911165111942016547982822220635914846507717642082242934377392953294761
Row 3650224952121335455764365243833254176336335189822673586476551655173212655547657382485956117316622111262089544430854825321774692192533892543500521128923950283272531574202521425322412209
Row 3734215564446552083093475058148434760378212765638445424791289108415825543351517351725417957142017212343983139440151824625308638491323338115894203241127852865004578513326414743615515923591598
Row 3873287922839332545544942901035487141282257240343343423574011162685620555650165530511552903915453691155541257852552254683917352196231740919745004586512954974690211615824960481443006021083
Row 3928038061603512845271971321826111992146175032063872621220610532073172632629298926634520279957665093431056152504592634812642408530893937807819438393660591317645869293854614596473045
Row 4036192514509537934008444739849863256104836274017164550641667452036201232164030043455344391317761849573221272726421002659334524515513563509055741206123053123751779551313263891314765153231175
Row 4180057755099901373159359316247272308282422255256544733756434254114424293730142128870412535087400423201558571734505453101272044607072335346310974265122838471574218011405825387348123213630
Row 4257550571018281132364794355334893888413846433234532955882181258639232184588837213071603272752754197485178342234379406515743720280610325152481226051478124249774017535646215517461936195072561616
Row 43436011636015852259818051880256620889962745485213035975284945763895285150259205346169252685143361429172534258953825873126151782947162233305603113523125354778204122122056402011172666398738413800
Row 44459711691889104637532945291727832254527718334732185537465632085115380124819021008495993189426371949136854743936461535591510545924434021485353484455193195260413595195189412454989287118311826
Row 453264342545261477299635604708753444133882366181711072262971694307843529864153392544504138567637153721874446330918411570235636724213557496452140424165114830165371209120714365903181328234598
Row 46103232603316223734932137390327583816152754932500367920792301227649754210241530452744061465358549832392254840512470541370125422927422047484214925721998595048842356323746177701690193535435529
Row 4750269232324434014052110221716725173424361026874731403837134156468359695791389872258544362596246562885565949494351325682192361191218794782157010252094387447342684643263409339611121797954
Row 4856524309147535824647393512365217431357425885506354270752625391253554651558212224886376158942420220559247184496194054082081556725294884396236301558145840384771431551592587717321145354155852
Row 492583129423027085914166413613816329830244593178914221157376556903911130401818447332661623157949522690577043744509331116622953491719543875866107146894285153321072674320358626602204550642142319

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.