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 0281843931558407843855414380812763403191536922293052913282156541112565516824701943484318039281360218259355029276622874602670284319475387124623903788237363534954514180938677773865122415815771
Row 12509477578553581533182850582070266941534653234023123296204359255983245215925288337942276827344774434119115211129372746901395574743795938565527688234136280012003412013182953781682172920693431
Row 21572422233943818377736415804394045211054122836498727059653088552848431786258520707615969494327464718526637976324539845151098434137011501202056842731446137102410431828883074684531053294002
Row 385823135308651417343762359430828084258138255237485778480420454408442358463546489618061476520033155891255191617652886127763570837883504153241281604490434054812343020353684206184593815404132
Row 436802684932374127924815256232523312113325110654813355835683273158457402221354206343527264593343827903982201380839729934736686302457123541167934409172355712430513893369103995024744324
Row 545631575312356225878408053084162555241944954550737423499524745579275357303125813408206740171936329059962832507528372872335748132278812152543881857841490221855456207249082292262237012925
Row 667324954342347513714006322859531684344489612911577349028802071350272405293527422664758488712203011221521140805235423816942042612559043311072906329964442162258409249001785273759284343503
Row 722211387598035172825219712151012408145418074153133537721263406856834322334290791951073927121520465201443444215533464266771236468042351483090245003013219574752701222909424420702016656272
Row 8505456054969810465730141604143873328043782458795204651862387432510471323157924961909692290357843582307171158424323935146265164252444762742306729874842529712073637357356102481213250332067
Row 92013011399084952723658451730235456534943221062166732204115561345564566580973320614152977250629504476739161249923657387218424048792160912742349346570751241476276027112835123489266855115974
Row 1045265904526212971225347298465415677791297813471815643328266523272241752321956351198216364711925818862242582536953474305038621888410373120284748482843992685863238643781847348833651003
Row 1114702294316530641141181010542175419036241523181096018959468231509439752054741047553938684434264442954733571116928995487564924344385151152113970267855824593347519285954542377117656482298
Row 12480055334385299023522781885312138053876486444609232103388017992450568528851064974496451023854515186236229662895350567536812094770378157901161495716572373224832944176179216354720361428164574
Row 132797391431621794130417052436315405936292786557019504735131024873428222438573301479744664070111495014448127123961197615212229156055571453539734975351221136232024719985526016664272214821092163
Row 1421034550138919385261312107522306057441344126328321264214174734555022275214517966123906765257191430013908348415487132019074854468590311753942902430533133190260220472216358325025831865
Row 1517888865851711192040182195476035911871464433088854174489653722190486244544477448328353634421382302207631104617683489535745910686261358605471573428143531896340010969285957656432045901603
Row 165010559128652750388847983885571289282998550672483386345661968278051621839108144694318305656843013577532141640138469657542062410360030769574246162009284267385549071109222037435554682410
Row 1720724712463957664463520459313973324650003835478713694980378225831323183820214618540137669301592488452124861188541035224596939253168143359544589210813475661435823741267200939002766291390357652415
Row 1843243773585513471756965599197434705466843324811871874380730041187405626504166533519582867559232582073147050893625226284633579040683015926529823845010921138512134993475864514990936681318
Row 195743407544244831304558874203597416432711383135841843740147151993196226319231351171643593378536830092659378734721839397511745887599311603533489537384649225646475807112845028862414340911001832
Row 20430433873423514437597731936270757202632649427564242843372131437404108972783477256191001237127192800225256061951482134555930222331695481334858575536338249753371810204723025849121833835687564
Row 2129346793019315816443518508856155014494130922832204248147115531199447293070166243435870261425865909490129342274161053133379303637172063474587853281692321653914621533451791654638424629773640133
Row 22511524121188215826250805936213247193662390881345832295589963388728103611842219510372001408425554945491323248261198230279250026723494964257657965257247240531440173422361290340628657081719
Row 234421293249633927184586818352481402615192232505328278744902322436968192490629415945365142181199281118683921242023464325785748191149928375828414250014087269232244739473426763073123415609
Row 24113335602611576545144893578211516231107596126831354568326594679294137084260952503428927214922496275559278835095421815805870686363419099673303126452941049727364154991163460438612911911860
Row 251135290522593858280051149152584300958701820254429665629555353818055939521934655471279640964314343195364939011522575266613021668381327705612134515836040311276224218959883401175621302743697
Row 268032520385942295553149751124964222153188118734124873123027561010548113234187509143445239115812834725514562428891489466727384951578421630612561425139453081127025122383576247055661724054639
Row 27220024492206416712453654283278055412107182612375727544115144415192154014704223551811579221129995345106026601174645470396226361026489137227151014498318551388431153205250209639862359172518174767
Row 28466342873851201427038224279585373651754519278715161607457571141481530890513723385582328417143702349718504677339536153189548095553325370188328887582148400724655491402278033791240106432873926
Row 2928023727302205231554146516572132622103441925414708395030502463257418855435491927094321818508648035580309250393145133537601087305685231026595503593824332562423155196036213012084343022793647
Row 30575110336592888560182916421769398144616852025856426152844383551751433031771113053043425226597959992557127459744071389362708524733235825674327651993745624884263942194640322454125575933
Row 31279225591951161037072056155590342712981183152734270558492042803592350455712045552829332892499395353448378170341911531379289128644238353447082052569129995634744364522051303983457535315638
Row 3216517862967981178410131017213124523825425733835497462941832848661223524550685753599882375254562223128910005372423897150979014194071422114673973936480491457854197376157471059560050191638
Row 33838170441822281590628586171504589536462914834770804763315345783614178300838291536189345943577428835471052106037903052705312510281931282316873734555511226121256451722322519746787325519
Row 34289540443071133852061574322252882028284351052555458928435375813258240285641369352653897241511315632228113832994491856048903242611348634974841212447905765441834834793464836952887759219340592845
Row 3513133641598417444823501632192104662166539613723195944352098100838385686359229816432637210532582490209012411809339856441626376546133515550352043835231659314982300233618438144221487416998084780
Row 36905841308945794923553847683809431719555502441411011470144627283317450617897085177533318312268199852542696450212714748151234729410754739364341955056442390449001154276263325042900412848042670
Row 3736095786490759905879106430001843376742713951924994589172724164653364325787623347230138869114167236440743110414125192633303823885218496446152839445040294243255342973713187235753807646791487
Row 3817115964280840821622490859823826504857645256351938954827135827551987334741724263368175201189325945752674117337782303118235614389577283854703019448243434646248224873977257842905269319743602973
Row 393821179146893692573140163313314348443744769439248933546430851203579347767288827289113882741978261455301453513213251118685181150582737155050549311193660354127446665531234518728197111090
Row 40339735862271373438953095858101424062318780204459533594493729865746457147122131165281717574158758113629445544518843094676244521431763315710873235538427604491240855223557521743911999131553584913
Row 414424577034465715225912217331732823282657464423290043934420224747285677436012324618294956043261711552218523664422140194941551260004184306030024175583317596330743830226525495939474640745301357
Row 425877270041272037439254252332642496816464724759839327043624652570358453794336188777247961208189956991861299032325340298827085841201584233655402775141519936703233538945448891537315443494849
Row 431565446840635550355346034910358631292340693662998118539932440178755653004341918921523104637276132672169233021121309882533036683924477815215679683905362214535566516823901129741272041193
Row 445327286147258972529580236582447406422238871974276153255043374649266145233074935228152883427732004488655422860259846035354522316528375429386524637513672514357347683116526316850791055276
Row 45293455413661758114355485316246110912827302124345543835579451587225533736442911325664387130953400392420618353527360824221106270457745373846258584346153558541731371324013901536863157792148
Row 46105016983867175566045931771471322951925802440794941574802936175553389928212567468348232861497536853121104297121451334034791826260831964930574343226055732648312132019703426492144612103
Row 47222216193557533352771864157259675496376764159805351342356548551671641275235851753429213059531745348970530981452307722305911108222539125438153753804768168422243261840309952943991105033594525
Row 48395436003508430048195328436622972651993170974349027335623547434882867454126328484032144716574525252814834875434325385228131040771092144438542779343344452875638769595918952911303973632404
Row 4956292701387956422611263227625664604187458424401018196746162261103354351329256395553381138563420504328993357487158033555112332295822554250666338558997105382156621416284266593923595791

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.