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 054062414383710424963447950084141465345459233294564454144878654329917541608596515793010142086141038992243200233422316564827484730348537903692196327974105342725140277215894344155985477401351
Row 121557052930516571950155754617125825771959357322244706230257082496599416715293409850985543212558185436556654155983305765213810093695130317272710187734439674453230215406771007384138535033835
Row 220552795193211522337405796917733622383175639261148389349354842519666215521072100555185525330610572014313489858518152732263946104664379094627204758271934251414474426828823673202513015623864
Row 36812634486819921582173125523584861532942230128855581910154933701855426921284574461012683048287715565414796859763942136636102810156457674982281921255468297150671768585646472677140420174532
Row 456724145310542825413152115996855661238165354251793018415119884581391897013994243843705108220542253755488156295772341353013916517358233286694741429623559785948776515729654926114515462843
Row 5211429452885255113141992475655395747363751675518104944673434156620497612235789505724697675004324459231969216910673515501231814591896573217723888448713103634212347631523172494358547379911346
Row 69711780403343925465406682246913752851353548891862716534737574471118164449332428527810562904243042271846301429632837436039344617476213731162416820553631554349061165443176718803777452423274895
Row 716812591323544623144226187554172488935032908324914371524201128092686178486431657203769148141514536336119283059568782232279462144267232603704546380044134341303334968327394872269355481558
Row 82870441118732590218033547407157142667377340134891000134656333671460522217240444356503706379133244526633025599242205894440393248458234463224129641605891506945603380685906301237394510
Row 930145955914345756054620124759375064390929615056212928553459222153384040566725625336382624524405238658314473229128432211801585721661714331317703334559170653972468466744524596152119118168595951
Row 104823420528643085872369169357022163298325454374378324015395497571323085830427240145226739268036785334420155891505059553963224784825493923502515563220524678261545963052398996359058947095898
Row 1157244980391249505718592262750524792221552023850175458343285784773267730924404472817701018332348211415431924111309502723091032400722059813725811260827775602482319783452576181237791153584455
Row 124245498751821442505483514198241246272758503554375938573773373915814584346435741865169335163757442146541589727295870514117165052515517201556399031382379523558652229278836238656113621666
Row 13514517072333308763584966619250343811516523242516569473302581126674858380158051237303556693466582332923551384465352175528360523928571235559618231854209920433691330445540252277175638364944
Row 14614163647481851467144165316449317082866487636020824404720132112601955916308338083015328711774344174152026213497303755644110467243115960334327275276183544352142711479542245114551455443741469
Row 1546034575276347474445318182484565424395980269020034090136231440504704304133265391475546712502693690364578332347381251369341945271167493897929841421633542314013323142554914684173835413388
Row 164778866392725233251765214022554030312552771553494844712080115340830583099482936912521229101339465720569756833260308444614125101147134457187523324795726553637343108926814473316827961880
Row 172265894709391624159374929360657462542391717094503204127193215498290624482976263119847092633307233901106240186298646679369443822493463133102852528719342894320336431396524436246115742
Row 1832671059271758983042342625311148163636354100162181910804314520035722945251042422314444331854342086471346772448332444185715438311355612142545612143153953765779189237739927111456471319115028
Row 19165744205452388828632769332149491482199813974805415111131881550723461211028651505486264320415863304247521318175566234634125081579712991944256546208934046617228928511032340038258141224649
Row 2026909864799217636298402038670559133562425252370158365332349811351276635754216941083714457959140218569963983597856456739634443284845925282488652624872224116865123594215214455343926565731
Row 21350124101899160927803562567418222113562216421893207283631521649568317439314568100458028092689492575042103380418986531101690327450083298545363586442351574342639937626323234913228129172655
Row 223211148536593013229334719373043455753161231542124262920269514332182749795819832369350713811314139461510434191531369836303016135664353081703257923512591895358156804320501237457537185122
Row 23548799105291643061486304624441004089286316311787493464631431135395448453713304510456083885478339284386115736805104279422759023841143420818694189651196922773513359940634005224512055139199
Row 2450285250251542460438739363882773509340671876537122941778575534365985162316246353592390141481191196421533435316912923633321841444135237160425223079915294539950581170477013512947452447872932
Row 251474113567373843121714492927538672363344351595996661330241313032390665333384896594727373953111615075304406331409199417745024561391528132742843308841415206530329952021191601333342224506
Row 26398515603402393242971355504758036593110583447494104103251266439256329387683151107859743681437751754871497825083093348349246538854423294922393470275228985802585164746832595489713465204960
Row 27428312872110536112605790373843546602715294217531983434405108218573354332153271052185906269018644589528476159345803572042171090182935782350161813152785278402957262031422631602435530850175789
Row 28262843445893284642492583471028381867547027711669518998827591018456551082636588018922914390816184944213447781379144137951167406921381060914386364256233223550850935994117742829823935529955473043
Row 291934542649354847333455337905467533151699083125335497652621394589056485035551228714542460528655719288638463653218433926964118281856312965152183755561855135923526263825755011899165053901546
Row 30685490244165227350712804945392512625982576251832936945335292436585486310644125104261943345630525645915130115524145202700925342211161519282395509613201521169338954038498645893372190922462858
Row 315015658196216344992159189035827212044382252414743474726625858489835902253399349093773568628041811467213925182581363820405595429540021229328655932118868314416146905555290434362217276123345806
Row 3250143274715278712151845974684291037795264547581948594841382187212734132204299437273641683328132675119549728145353025042177940171829179155344254742443420457382989402245961830184246823956
Row 33525588595029811249263326245161752575845443204506035854983307654137732610583812475053404198420412063557938713904426118273159514527761403945408401490911601583452436352181037334522944504118
Row 344903287536439554328348599639059273866429441875692145233322468159137261876199226343035215086139813671123474336601572286025621859222451718625715125752498437848686844070320401653719111741
Row 35241239024375544751446084414175583558650771154244616393012466921553197124026663772373710432640442151122959243656494870417620612771255015072822101023514239592193733151746438349534758305111071954
Row 364291377357262027481623654483927532328833576419210595636963360811433784461834932022521054305337955381242905712863539616665153316913911180198437551627591130784510348612695568312122323176426315
Row 371793175620371002118513731957499756621668585950583334501122264724191421024781817412055563271606824589447263056306929893070486247455107586459294801821492614234884784519982237951425554539855634
Row 38202358023754157812853592402224085545730911073252719525818163318165746211236364671225311243455145219451249287714905234251135125035264509051635623149251843707948227447803475422645975108414343
Row 3912193677301434724800468492474517171800223495043115746598545744835514741973264330190312746046834748482952793856487036225074254663525461346110314702090282032694323376915794068375415329032900
Row 40434932291230252450318349353251662214110655323835180207744702725342355734194551223921463383516130421903391431954805814154420342043179653638772730378645382943489140707785070146524717953569
Row 41481959893080121114529141371449328175285168816219832323655214150274190171757197545554699865262454765935277047231729338354217173418475231684332123166111485408334827685506579423164656064612
Row 421663136258621761145128415536138556114259311359481800483033665521997169767436572844821005561255871584341232118946452895255152313112261168259522147206755634055179551122054009287627565
Row 4345723430366114153511466610273097249106043291438570512243988493543355995617428727451683384931508623359535448702342110487448065539253522130501200124714714492307447528862011569987494640331472
Row 4456223194217224416713673105352672119753760283084825652369338327855418458340325564313384039291723483737379132931769526238554088347998425548453203178055665177553923952521044763340848894180
Row 4519902920374420213257178249385604551827282897128719907515374546884936284313405254083878322949472723254105150356615939321526512858958467111427393609571822573362615354323253366291717934215545
Row 4610522665953398254954899425427485949328934085887503592745146147292858419923382576456267351903999499825559157907691459894303514114876252931031305276259418268414692127422890238114715747
Row 47580380823231035481151250335478406659482684835140711621869281837439731273167367333863585357353145053098420886456916714652377248925002858400015332336206614802603900288637652769570338011165
Row 4828309684838215455251943745305722924165394286143315406323882019069548203438243188649185033178518042797455415075985719433615664556455111737502296317342460111590247915204139561124264234
Row 49443058636645315478056971100584249456542090309253724254657392749764774167712711947171817313061261952235817581326499145625869565538774649535149775232184546301321493640011746359319287212366

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.