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 0499732431484982177643293858341937962356181047164988529674666216151681577544974122308018784905102640224525571945391911281304839224648147811274710208319177191065183035845139287654133786238126
Row 133192238563154664501546651164965320953705569369462909156935634125406510094071134810841467388036038352513121837774585290124541102678196196845553665278712435614319116055195376152915304752
Row 2258941443008234759043787103129461711399222855963811617393023381544171316721237696405201142903984498848271546543531518761108171954861684885149224263488508625942517312449153399180526620335936
Row 35988421611719034960361124265397463211311601434728801026387598127716633590331555375444236539842471203894853190227043151590022035265510269734055692981515614513612459561743273841271727084763
Row 4277144836243640834815512022524455989129941913390463927621009189959571228260327571669717299049324758165628884670548345536474140124811651040401448114612282846445044318283944625789421356372083
Row 5305037344851242428995332913894214332514757124210095258249350525284343933909204756645505488938734071247245215926544527716671508310035983028237715894671189645912844425016045526277526383623635
Row 639503550504193215611272831711452536063724326141341635045550246715938373638314353207619123712429411483454530588844621358428816691230598816183213514969516692276379859999771576454653251271435
Row 745185570591720317154952344794389445330841110223735573975145647613421207631031984246469337182491616184014321116132738504264542395854513531548036542522668192757233673436223613148308232604098
Row 8302755221213542115024753507217542455101748642208293355562043180392897334292513386864041153017372022712993474815962753248910234363605198448794031424963233722713222531248493450102520112721
Row 9510435673405488258915787488455749609401226526727822815713714881366158651957631813666353550533232402312226799223410373827344254539422353596177647711026546132303371354747711409508528333041
Row 1041891862176157925422703932290045113755254302119172730783222558790822784719154516363883451249812808695503394147493564387426623905204142159132935132087426617137733495740464449953469
Row 116062762294155743721363408452057764336348047121962506948146741865100741425117281192467015233646403995357015160455144475155506414514328527543255226352814603053413370013093984242934031884926
Row 123846566027524926375458951757982890342939409994566442236910418744116160655244960550648614134847324546593231355485651785260866907490696421073085861684504333045320348326171321288345524230
Row 13355717022671942075510552314745595841723082944757971417977717843056549248315178289555803365164420122141513822334228542423088305100851923443923513151324577339739523473535339837849675093
Row 1479011719861359179749311549614274552137313611943269835814190248653691574335840224360747304121111594249653375833255633242830126125402166490266042254643461046178362325109147871597448232891833
Row 1553181672498594112984543350816319667649352302271239272152484617921435435032243036411440212323342593172239692514789148480847163624199350295782179290424831872527256332747434967630135672611
Row 161927342315323949476139451647476867244004171573948446764776351534594268642438045874188317311385475479313033734397358485684125139603841147517345205117733565659365519981756141345773031502019495880
Row 172607221172936151691142446903351241511942841876134527201190463738531423390266345161636431279404325502296156884469206356215091514792393341455652137750941933124313528925470634574826111629
Row 18599849551181889204778638664197403844834318248188745133627598762350921031758108358358965514494091172339460613513993365644025679414343773362108814324472217258167355945813429512064953463
Row 19285533903336151758891910142150272059151586456182893262032106725001875243478957654863246720001820527964519615106891837984133837375198370158924121210136113150504257146245256603233553705743
Row 20366733632501403810122945765990492322045883160840179542236241633064618130143932529698534046857133964303545820404595228723935355361517525680244524041540465589670568320444985740348534014756
Row 21341643424835371426961732150628523782247731245091521453595295302893053551067596024939821560134362914593423873139157140212200157046222717241542224034355828645824976316449673854992288113601625
Row 2242722184617139785320324808435304436464494459927983535380549762496241525774938172741653917081820981143524011055130900393617505483565525043317593238633544179622214386546146383668371452793536
Row 231659267137251412314161041216523846256735043745566335511100234632892643304226064478214100250254293139227385056435330305954217529145442184233936524676454031570275374448821602823193824945422
Row 243828892164955305419567442762318510917443786563653945224140407330977881840651827259915159432572721135128271703109835615357350549783348479016794290500223214799621643543898556513391828322
Row 25156015529084551218468528735127573821093227472138821688136584264253151298204221645790356630592351401538451775370876240125931639194844825978120625952092280187919085823593637472757358047164019
Row 2652731347176742982530950091459292852421662986307522672087166057204726520124927242563705565238302226196353783627625280718176556311475362927228692579179454493765156213412303194721162260392
Row 27307518612086181457595531642713159355626051972525132722619383535532101414544956944066217416601929148641201771763924486713973577484672219142233150336882809172227845717921363114349643694421
Row 282231151326414861331265130653402416382453611605549539536663616704346193851614224467823517964061709394834472814422617793279034809467639274387215347653644742469411507356665362283518965069
Row 296483399606526832464059370054023495898644119319820864317280057722914509310145755531129011852537944561412259641456489015433446564149123716391456584383757269725203774298025293319117213463525
Row 30312655841443356452674379150760178442964752514132344221470949315745568420114431210121061230345898917941734795432340599566512625865686462841624059568722084629514363691911330292136434635
Row 3151141070705125316771573495283446623673239243096344495302842189667237942663392443514137051122153347616964315464317553955061540311815879170813439922931153316011924470527379818466628
Row 3248883467487597044665346492946631108410745293861107876549917312124403871046433617123080323519461771353150293025420784571483137490347363495204636753392195350212581184819051910476346571980
Row 33214340892673193247803454247113672436370465741804977620231659391619973145352773246533501990937744862583938251681812208461593736476134679413439015282214312032815751220851841376409840494825
Row 34218139955622597955182568129135914170286510632471119438023005631148659014570975995149472428984090436514123404522159913134672429731175002382113253841148245051747573912021426944117342382275382
Row 35391623432277557359851913723907035904912145110453752108350252365485119575452279331343506287257628059152634612190710357493013863554136634374973217466652435775778484320361499588532833976
Row 361258447944541751800415455435670120215813717248638115234140117814459259324671111361724451799233729017074590557246243873587614484388663273178812403813561317431147516651914264316734324414176
Row 372364777338512964365298032054472670309570921151033543331621920256222131234545027138712631304356695877269759646719483449384974338211498646514041662744331096394317632994584040662842
Row 38314663617792668322250253633222174943631593169116414382131448523431234424966149510883657376215240575113204248014303236432191811424475417571486330713391591272433674397415093257458714485906
Row 391118140195331281344176392223071108322317815563509187854073256295729573163220458397142008120287814363731139344063575543558915421185176417831108510022465832143470519623185344452216795252550
Row 40947505497652189433695898191529304812888319912264148509148415109250246043652173479141910912065217535371807577332101898577416945156238229701592284458083444560510627169672262616640403943
Row 4139511932535224825280288263512794078255917082609453544546654424100214345745625213629814686274339952744344813821496299517364523513137412391677495427367232394634204155162032595530737322073165
Row 42359725376813201300194230144796418127265012583199275357724742178054215917566248614721103711587028104274478218393260160748364750578654360332164492142860549322144007275234991517424851352312
Row 434193169559614533349165025195377153998151303723540417071077303745411320125674282733664849590224972174389244815688547661184139962209466811631757398158362775744476439335391466820605388486212
Row 44235957703444281426472553553417092358100431135479597625658292756141851242024933256725661575315967408925884455230050393823628448234164098455156873437464520312916379154604314784418585547914585
Row 455551858342536983146428759864504466388226591650539253415475525511192677501016064555401481218391782443545862677140618275100770491554205657486416383029567711545283476383128021670429384840825987
Row 46551321901618426336015315362401392541574131129753465331103817051483318351426743231586534484124577560013865075147650481272419420231350273758855009127452584831424358522399559925792495328524314668
Row 47102039277415752910568975516156434746273347011437510036682783221591510734113199115205352105525613530298153287148532442526545503190171592835243110539382356038174642305630354986552630861136
Row 48352926505497156441017955024897163613847501827544913304588546467469254833125468127575067396047343929431546375784319085285046715327895252446544153953451909803079821382315966782693745
Row 493671163826541028195438102530327747544286583458693840219256343086598042192382327335021771503266855244532558496827518311885157838285193211813214047371401562765034590510051774445107341444937

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.