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 0108751945848411164531437615520255926505953694215965057011215158411024882156210024763805439224340813604549652864513232430164535443522031459539649921125668461842544863244838495814281015233929
Row 1165444565912214027623100593222924468451293029972031021831291096157813392247289423552958803049222424531554248343535288950758197510609575664452477778317294465321357395490524351402736
Row 216162751392930021734281720287211863385919801975158650595467184425506342773280205473214751888503520641885468674506356558021623541444872426138052243888347131995870133826691567256255819993122
Row 357162073578841443931241441568137957012804594648207331510445552176147256645496168650732363216376555445130509138511514895593626522084422339824731406313712438485648523588560714842248719578
Row 4529293614752702585285242322355300569875718751535480411602314247438131732267655824198222951963686146611431586130957801620100940063746774102816381315313552906721986513025071273674596618504068
Row 5180619983678421146454435232365117151337857189713154451395447261903342169118532664491631882331191023663539451019765724192228330436155544390541965487574035618695239448057305263284023169122639
Row 64049731123059673320533747191394521821285724380248062927115518445662592344429003181288419182863205200559544555906560757583852266328965715527451147595589407729771533320022625849313712393384
Row 72059402541250591920510358376640125434976272622792537422127181258340025294577518931829433321449729003367110343952916499611355237209328402702325521773132413156436940895012312225317839481209
Row 82173395731584036341357092738366438313829713732809809508911474832339014452441290931383067453115902402403410899823562266562018163007400935154685100913373911965440525270549962463335542531563
Row 9560331637351288507224793432525633730075937367342512650412314111825346174716605779311958115226555349005527393823303513527223732826509114962304567845541363592832564124913553212543795536701
Row 101244557136531069464643855999262210019483153446119106134469451137531418373818324058177354584114416332242584696669682999490833240153892295910549283273422656271713351119852741170821020192374
Row 111581596554314018138915035522052587147244897120773124198887748875987552818334211433853031540342883278992172824916653452403739379125118411718091226499130385327130819323226332226324255136
Row 1239621336406156881176567752382454391273045005689280233481038349255313534454942304827307132225241429223658995920376517131759343857216874591158451435978308437273874206821842915877333028873100
Row 1321028184631294335046105677483033344794257120765215385018302051530422823645142853834463019314238928763738143859641434572818105724901483053115290433948655338119015273538240284626436932293491
Row 145485375537941629165801441020901866523259711817511522682939150849504546466116191052688570835259462915474026285567232369457561349576520533060247460850381288564235261362231012171753277746591928
Row 1527052381322535310105419222345435426249919642175383267549955072422314925851434436494832488517941330472125024366308859114412311672248681344413323748171553093464839494122851271921154438425592
Row 16423943874776273614434763264039644914344036663115454319564823143353841540561737771124343411683767113324639933985182224122064400454022532873439440841155542781422735301122803652458769822873660
Row 173344427415855693493254072065603568819691001323940874321208848271435372627592711992157464826796925396177224884767129748324286196431383603454425751018243539849735194313155835961450109829543630
Row 18136640974009488320854509727287249514877200567049033832246620894704576341205339568326585754949140139833253193824964044152293347075395459336525291182536752804215376198380011144287237753544458
Row 1920705563154034293830505639742410164316470636014346376719241501712139431350595825227690463522415547263481676221055110244196730420494329272592434783097465012664566348937754576258041495445
Row 2022730166444503378608124437035593120436210122465368408841433865123350183501109621129392086292738650255452462361216986912613440647785924514051803721125531116592711556144885981409835863914
Row 2115565625282780739964184188843012991303231125994542348289825032813849499558052334145289646871723363242073449420355844696315514472203413328381998425349117563704191857465271831263123361526338
Row 2235532818107229584440549636834886184323242432235497769424883031392148075042947701115531531995019422737753623125656164651302035793728156616511981338921423182614430010552124322523139651946181
Row 2346473668462538922857771366418815092240010558132495840309933282164448918615223382648932842599943812181567346535491788146933681231128325821879488220341455429626694543538628081949751482351554023
Row 2418796574705324716144454242625643792689149738542432303716472597910279955852991465935101235477624841299424121944791499722632107857325969318435622949854470581316261879435840355751912845769
Row 25104893124125306103544998412888353433946931916239555358111322457148614807564410683152241170247623971386259623388275367346626685659941487030261430896341134774482278229745895556573755405668
Row 26318419143106201731741745972444512224174282159151152261030445826775569251107025194166562711522813218433637246325318533733112178442377274549402164874328258471448559367442252452471257403221
Row 274697222819788324822011284421421888332335415884485963449230025852837424124538411148550116012595484042057115998224218233217905258729093026953294139745364115818569718304371180196445914567
Row 283943447716994138153716423951268216645910383346095372482334411824184490929454012142105656295593112754641414488747182595152681351308915912635275152576427994489299812201347229255057773259628
Row 291828138528005092212313839874325130918686125132671596519724927185852874360268354846631874571050275455133939232681173112303062296721582131390558633583776238245913225564451322876515531788
Row 301713452615424665541745431494221455713401732127243632951598513822351399111756104064366889826318914897798228362658582419366561556012316122734176226802465208511201264220036154492261526993527
Row 3128649015679428747804898595447334302997559250343155432631485581319846503483557134853349550433701355221318881446430213325964117843313226228550755944266332648613170164275747669613469486542823039
Row 32325436022381438310062833492028662955333740122991145281453985729393849375160105721621797528328650275976245341902001402817357654853412812061112161031263227164246212498645480827353860503112775323
Row 3319844158316523734077437302910832249243320258745359487314062922377925708375405462237585733191488356226785033231240698245044107344950432233232947925623880456128252524544022422984263320952971
Row 3421658922579458013050972116556032511446458215074581048891555625116857615881135614493653521554084541993761274352225347126922034815254574212829075971308045282858533313722484387236610882620
Row 35244457516134502248137722541728295126862256486551225852451614103473151011420692295163225401841110215201400382520849344736267221905093682522102527962079161549008953889202540163310400947041094
Row 36110542034073149332348742825669846349362650553253504953211465844999582049713217485135143541191825821670538490559765229549211287565341609389314244695471257911775211819283102592727924107
Row 3742361893499934454902086433559683664375848043542830152120829115459284556939951236691317957643583460556693160408126623841717281325564959395943953366438950233297392402225326385367382011602907
Row 381816456627772191107380919191124612341257043814474301548514700241665629141963317722783474541746971604455235140161123539390027881771120774714965802286836834133401239461267619201638092401155
Row 39218426123171516356701541268562758765654793408457283987407648071510877202840725673372980439175451774588462450265974528356142104105334724515515281750105820454351893841360419694217101719091274
Row 40197111702838439137902266349317543216182833741005524147894449543015055489117757958353121120055041153335439791134481222995742469514182274297017734353512330263640369632385555472456153402455737232685
Row 415914191427703693153248544662243286150731362368755693041478642312128300099641059127954874955472522027714992223555575405136743154426533423233650523721449025973227697005070122458693704230
Row 4245362403291115113271153462996489819464684283447628185113553248211406110050624285442447201864495324491764858373415635585507451703351399455342020599558672112240157764825704565833252464800562
Row 436831060447540322918134726733290358410431024293127754439282726865524094473564840502852213748201627550718174683120281164370641162215652226235728393116474746736029185232254937694394
Row 449055629404155311832418814014599360642784021525652981829523915875192195514274306495926571907341049344222663443250463954582578185455635205583376520727153032350139843944753500110555229361884
Row 45541651782607525442865780151950858851778585310735281206353028611733078017523841477198327183325249876958884666444850326874151474219863466181758098398957868387771811543025484646174135
Row 46227375945844062241957723038504176223801121322054552220114622695571196629312446441784435312412887042504132441116684835525748285922183961962118431369320217704893520729781332254502226201363
Row 47523217883393496215061636464594347691085147518271971913295130714440149059080138202800266646801626538544251183243443438311865243054581381283434733477536545654666877812213536691162351214543472
Row 481309468931036824149576140231262532110723515987140144418215666367819703399402768924642789363048303880314733327903694700292524923270239723044463577256815861420579716273722218526641405442970
Row 49344056733393270412362749565427422355534248181020846588089911813901343935348313606152416684583203341553587433822721903947127114963649327318743281515437637025841279553554227431325831465439

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.