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 051583884833548144617721487539541851555562848722651171486420435232118418184591353319272189707278454402145222055671704340947293458521362298752842858188131486302583476940431952519587310742982
Row 119281697448526364734332429555328574455902498534753995603799580941954029392613194546592518813799386918753234363037724304286429441718471040193790782320511570660247712717272292359214327171568
Row 21713157717611046390848074728549147112183254342464338530442451389189948453742258040991623534837702595139241832233638336635142926507637291888480053738902925468545091493491155992982988323825673162
Row 331886485171676396290444452528338622025977796376541612890264753962623577712954248366158204177238745603876215998837102442318223584530481237128058494748254554026991346284910555685195928021001
Row 4232235503168453958103819137020434563239749522578428419003910311255173623233358122315974169457840645046386120934186361927215244356767148832988558256194540055584810588228805819148853305814128
Row 55355592252185712150656925013574425151235844836274747655381637306222012516194330001664632282142415861252952624071431154511741464201935282914282022393794308450841009717584651625024458738605918
Row 6379247509754323118111442873627552793158127963184595325053551281844012072156049945398189345291748195135017821801518849032062425721222333409848125415348255469323941880188141533115618335122
Row 7115726873940522843955646205036342133817493303304525554900665163630684657443452867005675581760322733634039300738173518863888784867540448736303034191744981759135211848207719943763128
Row 87263602711522466295317485762225219024144524959443952712423417255017794218447435975451375140156752915412444857419804132242548964537291351673282895134969427572778559318734230256448593139
Row 941535345225353174346636365357721994436044982964562750112272460564852602141279425553805102611533903409612883703172332324346363416413944590296111865456596851282964399347522082567824391149062385
Row 1027882269294030175329343623304268263818991245365958636132105828191029994519353342324804979270136714999770270341325185943147512858161152854434442845472461220320862303143131501808555549714350
Row 11463136858152344135536157413400402555611227015331178156144481525248325031561940097655543903870127232181729307037294088324824419652641201425431379313734741072211648201262463501517178923452
Row 121012400711538945813524398752743675127474132683092581921603268230574725763967490520581959107024162391547818452634137268047473523577334245797420556592772448548155802523857074929377281450872016
Row 133154468634222042598380719825616534127423312499117228337024322580955153441291639453672926573035135942586984540834252511912411818212450518920764015410252173227232046624412825796483679570
Row 1435114503378458434371237752733010787664969315342371113547737542359398229205197277113574719465709444216694041313775561735734469292746023629554555764919356613674207410211666243837286324552262
Row 15101148404674437223073054632990464513181132142811173359303737767014881029323234264080299469749431593431955024159501345325354172546928444168584129434899247124552224345615985690314047707713816
Row 1627214113213154954994122588028942769574531510462619406526384069210732712255545037727571657353132144171931278078313721742681594584466759516334234320146593153391135611445255534281296284831
Row 1740894837464716742795106317845005331571576336049012360921182251902149398446133011498956681841191115940035541569355552710361542753946228525653611540434614035290456864580346948874952367244333533
Row 185896194655903028306957163834769479358655541539853847653581286574551744321356583523993482330258115844284295041204767168582654987512493414143252892202114626281349275722323968178715504091279
Row 19281341891995583856268591366267920355172257436163233124875927974294128952050021635140611396969624142414699473250505550352447383988508918292013319815534242954292283230521005911433048952445
Row 203763410838492565588145027019961347352347614504569495522643777530994233237461505135580420536533175218559151927250760198167157153352584295241762531545919965199223254284466120233819652494
Row 21382623535808315610304404115929963573856207620551742278679396052593897528259226459186234072788505231872687263524393047855986613342812443325520215874031416952982872477155572963389616982421
Row 221003552636682309411147056664060400632161634644373927562793585156811246220215048451578349972032962660873591244515259391453684123678563826646281715477218524694280590742521563659502045481268
Row 23382017695880504357803915376336305960147435476233314511154586672049929136712671451899311764134266917350665468350120631312366345781145611413628546318235625263435551635003636478651372746
Row 2434211301104362752274409123052568632161293466731995019500980435828542900931131943941607514910813502197917793814512431913856812462332933824140237946044255513951035742198920704114390412932183
Row 2519923045171257643879814249184530595702145818621940143311384557338254514646593604339137389018134478390252714172265518704135527425713085390162137781897219636394954221737535912679371411351029
Row 2614753763192238514965489484278157495863290358773232106624072785756991198343459372127104028164830441424921522334044705557509230321255645897505445353825384623971342900596823925226411420085093
Row 2794816103778221314085167579891929593343352533551883969272347881179495229083651124413129103771730835153530233731431589275855204966170380320872859223542603275494212331734014236510123162992
Row 283148298841851837338817431156467175055651848538753741152528118324915402999236532574268121720194794448459238032399292833404426337742344521855478944241546259550423261467243718051254447746613627
Row 291562928183459564952360030825802720178444105060109227395355481583885420019989394396664259268351961950693285416754378449398354415122373915341947411780468838552715372929207492733182210
Row 30150851765029214224928822962554543378262914155822642035449248825014612542448305148377844411110405587948068885082245326611557635201131215904326545395274535560259064992381932821228385348415721
Row 31460381943315183142757603834748318456621294597135823108516729617255225470016532910951163240941745229342189373112234578323642248146941174819552342811955101646605949554933032503526815033279782
Row 32396450195216440518654725980321149091847301624335927462577433394442094504903845413037773926144916392132257452436650211024713324414515750972481343559785112545449402025483530516024223061
Row 3324804227484945944031449427845514573554624542791329519059821784329636751329260341565942808967505424874545459831804818468015212066229179728324790352510003709110237384836014606207824274070
Row 34399738682484253432055612243313844401924630447432832521332099058724814589651285377347153245714194045651032375064577738182234238486934755463718170312191711386837524835337848653560255556471468
Row 35100431984169782498323115394245729574763366039741725256627883708164889048283799212418341885458225141433831569138763435559413555335474341245726188726583607527582101978267986512027276565786
Row 3611146001644352952855942499514029531326230128565658269925923079131598298935402940324444556010464925138419191341378658536502702487451671416480840834942526841499437723015114312545098273120
Row 37111945273369434448243412439270138998584884586422435712187623486672589918293776312241762384468231695196481354501997268652221390213111812955319941883801464901155215290030125770201026231767
Row 38312429901287347705998111836429211051460582330854509173416801671201048071535598326852544201244528715145101042352693357568361750464589117257368691074328245061278812461012713196114910
Row 3929854193451846871094115652478423882136138282706433245472181372045591754251167827003823298334455344297554238495896744169467722333572711664122456905489733223136331520741728529756935334623
Row 4023874466895289307617233870380154345977479641971555523041691323413386288214632512943236613581497923201460264659763788771580561651076554532269876633563680127648453192022661443417
Row 41183122522715205555161958522422042183841970327336461040320258965589426031222315923145737199401725272959814709514950255587380445993969386553423521775712491753245892125320706625784281520223474
Row 424913912285012418335110351221583369864556592721561031233838626146954246344692522229692147428622624921706521342383521280819916422270558114345347432220361188525730065535966318249672763359
Row 43912043260816422536142010175435406440002115118023597056125650196932935483190724001036367310182767488928282358221152855955531440101413205728274271485954334475447822194899412738774140178847582395
Row 443751304051479825852341847938474482395225925955313445225873715824436416593686527624204749154847582545691825302485412254512178486029191172494449013465571825182782215580028711135540949572577
Row 455526338768552262005451621284595711577712683677061180474357413568423959773253524812533585235116637388502552383785329969254045433252473429604456314616497531075350136484996631301331712502
Row 4610122606433558333702446069836892448460441922292451763283630911264225486867129235811270178515469851035342835155073371244221781529517351319763201414540421022042297722904835353279558453243
Row 47343127675775211154574164207338322471648529427037794066335247070913225603374225912026556997290413307021766389741163768458553853291662576115233164214756647538972229467351875486532547521888
Row 4840003057672510440548791712582383834774465148721855773863208645513961668164621015922567949133249274473267336113662132173049521424132147632539435250254705415413294181281650291837269426374209
Row 492295102130694853127479311418779217162858209341571278207027553743413932404909403822055431545672050303635137150234369204938543172204920853764550235317802933490143761940228427852818502851621655

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.