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 016724214528136596257685887498413254420315611265209369189510419641804209545482806565137366614441807427226737345657497413855104350044524973636182735294616343219987474361736195819321323666
Row 1267156381876489017672512831816325831802135670637311610125771405655324407322321041446474958433130148166944515376424058895642434133043483457859813407874304496245121799787503169356325040
Row 21591289019852798582950910964398501823487422013422636573252196842045018154222214338354460312158724236343932053288175445691823186457213290173612215661212144267695226758698438674957732495763
Row 31214451049625185926444720552355465617747621599511246092646275546152880126450561476145234774425411089249227823676212927034831321459972584132333031272298020265408165898359625468373262915485072
Row 41237510752561969854912524434582005555541855431590524833431587151629982576285639981431379202176516341008145850672068118046953094366010325758529422248246469954185324442651575754232040023069
Row 59114965175961213803116518126062618624378927063756572233783067412458364822189138923569211144993498349556224754151688314477742143721302471222214767400435818994924208139624114467215223253872
Row 6380636511899320998137932095599125622105128495955071405347357811379523062330243875182067113223527313953216111145258236631408262724295448546545416204288258855981112246535818913572545
Row 75692454970112723008539438682928182926643765188449745963133865406640915953641263327541753156402350664804555756776445495557763275911651317285819744816281956651584537967330835989322820871580
Row 822014006928433952182199467447493944552053185322388780188933062664405833283941589634259430934068205714351667528396240383504559555443652482956782243023555614067947371999541285180536324953
Row 92029755311943399963850511526563043392232033774264459645965268275850991688453743371642154516515153190588517023133252641784384487282886219224921365442347974206173828021011809357407028751558
Row 1011473736562314721914547216344534955527030574312191026204760235619654888336689665369352640135352852154011005365146431647277840653025550412367642800124123033622215577357631469292330352359
Row 11615075201438783668357723225342475261539048373797163515602795300412372879171418981763250369667120034202226113049094138387523705341349123176015333898382340652841579021802904150548193522928
Row 1226968854484350349211903622428612575491135332595555828943922611131314702427756525313265194265659825278362513885231362626624905449310995154489911835154954111056521172110116644739361441651494
Row 1356245626561337701062569612402579367514872972389358421110232326371302215936195111295598485221526355392459229181064511455093496133014242495381243454051373445605594556290851738722871188359333670
Row 1448791748251657272816327444265400472341153567267648901232335529852914558749166734269493115114385249715845125144448931788533797961323961726572321105720446221101366470852881281285367251338573061
Row 1550529082239204921834170139533851635260232871229596838673019508523910896303165394214451341220530265125503794224334362459336913523650209817831881068491838014713505531430045842370898137683375
Row 1646203347388615254782385430242389495337375742307184438292762639107729253215355230363405266724922413276012803021574226393777485350905926152489488478557436983769258359382918231058307983488220
Row 174947252713203401209440817847835573179957787902021403033501426787172338375329364343424018898417752744447549735365226278399915474445177215613721249454965670489550224720169334581140321537393761
Row 182298130136849285833408032322412214782682506532861832347145902965546454731205565883245728074183697312333333585025684910353826584001149819951803180324761626565542153475008408928737691873
Row 197953755146482843833712813365057681250298825143035406402321814802554149196817282805347911862886109245813995056598546144831981125854051196158146865598171712012458393446884138270451715386474
Row 2017421157375258744209421116268332911112119975783488285680760358258352111582031243030253648058202064336084518765114194251327339753609560142372442309729844422957574415100239083054405008
Row 2138725260233921174018355824695389330232153003184755141835990500523973029487246371362439846574768490152554394209757865358695410237451384500818742935205952354241103263244291124614436978533201499
Row 224713354323917194477172221614865351436592931885443425153219671660384539684413165125303770335744465503156314741072346751744858261435056984854419317842772271329832543253248885471907134715544084
Row 2335145358519747694129760469430761467566219930333723290564243643766320147784052553024361303091268086049965216109222221455581239362689296360526643623527615202375478713572442345740223714422841
Row 245840300363193544914571124757903153998125713983233150399955467478113464209404176035024657194310444331386924065398109817431333543319635146276910903732471896145411581405749682926586422451984
Row 2549422708357430701767301843414179259133861947395936663838520540485807248459511048160654441737506239742578536825650467316145463383455192924233618423216133750354972244536393533144641391143335821
Row 265615359120944531582929520623197129363146188071936352971342837094083933373227141852442958430356215691302316925797827133040756240835861646576418939315112246514264196662791219157932558
Row 27201733031733275139352689782414948634794374619274524349078037763495108622684457191518945167015107595641754086489626535966503010062267443212493370507527383598105449121923494428081905574126351089
Row 28895231337774464570549487985928935111862353294134333514113157431053948441536392973391536192097580305956541109197319541847365630229531507478649273907729293941943027146421263677274520383758
Row 2943074961516516331873271558344114241251279326385804204025045865545289331825225542957902381227639646943899749213562276996221492442116210841842344359401383062403139984526374555656605267
Row 30367845452696822399452603606245532283324370243531812934970572034585792324756812072022237252744443509397258094984284812821536845378697121446501662222315939863538332239681247415222631192862
Row 312428235919595730223711564536052642551451457033551215543918504410336716761992578020987552806297038315376218318465818322256811047408245113879514048405574111656994574369156803564377429361582
Row 323652188451722461148627644616322247042342324628884512696411656041451453358413085987244043001863517244844429382022853181349722701263517910084499220316433709472244202405156930083134283585526904233
Row 3318664150168349139202411261434945978771640222870391933081692113935731575017306248902982118665105346633401661389380553445633448742992833224625465185311448045295171915938503114518845291922
Row 3441053830363433384999826105344831282555549841837146952444256641921131659747033261813473155174658257817152284108424236185700300467424521805943290318888364644925294878126204257403236094474
Row 3534425824258745209133954487141674007181232314842482429736673512270546724611734273121528691913442614235317972180831848673335546135551220104283028611261859287420546529482692116586610092588
Row 3618324476538527235056485258415506537727542582236371650161630518629023452402683586821252049460970926702996346116634270335520751306981334360117491402029150176633852094321441473570269937521248
Row 374218237239639699110504987159236882889173237184866341320033332503417644793678293952102805572443205245464962448351436413746169229362277763499846721213046323789451024871750575151021555728
Row 38596648984557707302112075794275840602163536111054581004530462312622490178714881646181782323743510193311502220851504845734716566751311603252352023045254543112754261260440645951729518325534632
Row 3935542369167324344488345445065529285152862510239321317115850550734445371119332814551310647784479170838103694424952633265640264580824835775155956455095380526349747403832231954251347269427861118
Row 40412596158040123359904305444634417478551053651468218033577154485252953142663132057953759157375271136072432332200758643616205291713503945225309436151215188026904110268253691525393940263297
Row 4131163273562851262705725831134738509839725859339201145195404561532632447444655426862660566581038064711470115723390358124377162222847841771484730755922527142661635526534815311534359811157
Row 42384050761717490056802586133545103652175336285415512018339840545708530922734412524649063747183023353938325879316357271000533641631813708032069363860001669255823014721243740305351161352394657
Row 43167611844038590157479035095878461459651471309524452350363236678521000292613558142025408134713481542397054516285103206030324676342195890240439436735378388158213527437058143850402759115944
Row 441601610519730773422560335941645828383549504574144056484089886592128182002410233955855227533445495281566112451652153315571344105459972155445567413855277932198629241767179323041815893013
Row 4510025462496869728873851179433121724340323913060995574726513973483640075907486757165473664258129375626298339633999447566540531453133618143609584211654623819396551392794540654011707109539284790
Row 465170334426754868320517663079843158410261528495048361169484129832848426936781097411151100858673230475628825428225037083322281128132338534332961527121293317535616233045972525269096314491265070
Row 47170724147598612075688166313875111200844254911357517566565633731373143082882563527345992850492621145845437650722695167361040087652784422166439224921431815187404249521452944787266852135947
Row 483122219696939751065220954404424524524182296303435853162351965182165596672699394852853905571570289744373657174256693127168734312575589507154622532390151134941523465941075992169742783678
Row 491732360019993343362818163214159710793649483129092071139653002945527659633768304921534384505740701599129423834684440757121102416122681185276036896693821664207511743601353193541313566472656623206

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.