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 016535287258134042458176931951921343912427235192825789381043213428213858814935505430147619153151389228433830478820114452655398724275297350830051376206418575249965286515416614943494213554672
Row 125682919178012181927768351910047961432265881953396436292735383945182762513638549711989156234743271268735683645924122533574358393755563580584851103389577512565199266050791278237376524255399
Row 25221199245591106430214141288493738055909597013605023309424051958484418403136531531491725411524861307274315001098396378129842144765542468846602288433144794736436651365765330956705940509935981122
Row 34272300241155618223348256222743281468931869492419151753842282837974451213653614926437834772735222194858195211914738248816094703128040635613355292647814456435923475602126250548931791630
Row 4538115831155737570077538788191768366546863043592243849182287111640922485321335272188123418503173595936363565796406049791188173490271236647222118444346634725572954142695784423621732410689
Row 55211487057852300117147746944726134210108141551361506538893413274445853772203057649831341909274529002250426226535781492535955817532447791860404555952037245534455016135127613342534426824722
Row 65755132253773981190626532446604347436134902894280063432442065502497140044485565671780579621965811468254028649161933196824093108514842441310370197146979027825876425246851169187845791535
Row 7295322191596506183059145568547951524953123812473714973289865113219362313451717311169120615711963645343151243731263339002243382639274678291337311515334017520042454017544031631320527156025252
Row 89752596141446863417409611082423427755748725125514958562937564738534939450827273270200155595804176647013540273941042996405932921183349725665333942181844001362465211882480428158674876266515952506
Row 924412929346937955705276038701012561710577451454419110715333927210740083554386616163738591842796534734983213537975923263132403161197332493886346111451695388625151983870255248495601419144103118
Row 103073397300736643465806569442946042010482748104757271189626498171797701363514963410230551431981441642501357241764408216212548921199324352224182362353210784010169935034779123296210031496
Row 11271547147463114150348074541041378484637281860462943165958245511842858469361422433194354658555371572089642345254762282163842319074337474536422357813405949385245501364431852120146523813
Row 12554045613665543797716321941432696475858658152458329431141339225051155464623852453345621602924051111045033092328626308361287394285113482510496949844320452928462229551143894816123738
Row 13157825375405341176302650001472292636861744170430595413512507431272967161107157932532094676187642759682027284435975837517061450994357217658585821503717894623423972847249144653402623452565
Row 142787548436402851014152574854014893531938121424144056613960417436761441267573067753174090114546854465154251321908126554045157146948417825390469559743612960191619454433482966567942131138662
Row 153048519643365061306025128074417130331474592194934274191412945321502670247837822740350429125158504998118554552515116605003572612724572294588368913977783569530226972689284131661296200712945545
Row 1658454933270344954692238042722925290376559719491731433646912898230844187914794511921363458534113473912505624336311240434612015457274928794817482640095207491645574686702581690412195226952794
Row 174249110314782453529133334747291330964363594448012308339644981023473030915933206632354246573053833465168640831362536638642840570155952517484114752286588249082408745572450632075311275533914903907
Row 18574827105177153636703851178107325193267830331045063558468261079451123920597611335560361313323133581541742714117148893322835284356825785716181122501000223517020664437210114254405250233801437
Row 1941965242295037232558267675157521466139250815385287140454098206853682925168337305854498919105564294948902783711553823304016101259701845525113437215013337422546454492218351251182848508033903781
Row 20401258164225928447526955257353711041462777335135055628418214144525219816166374452752247146562469398125326855672112746301382209547323083429788363989465524325045482519821564871116951235559
Row 21245818733493286342464880434876338601989386538604377547238152194862205146063182300645815111231858794553212797524575178316736393983461469683239814667615513713735527476124261697217145501862228
Row 224795786215711462779569639534411131119372244271654494822282666307834722308369260293481941683716512711161672467513438671131281443030386842115469027505842261370928935690541819717621112
Row 2321842367526612402462626556135265226262519003094381459541032248561846021436473825952859225515584212441944161022689418336117508444780982719103041603295416156031570302427321373708126753805572
Row 24271351521274641551729972978155849111466150139834175543732591445233115449665104174755023191197539502030429701165602303553235225055371307157807713709191750986721158123838004986379450442246
Row 25435215667436505253467505622824284321040066853259404082305534635864212202379639542426279560220341089185938894299662233642592435221430989210252324450141585929577012473784431351963763
Row 26406644255033275643499420524070485021801502318849392633278117403450776917376922135210405144167535341338341695259239045407744937301116311799178561854143059194231451284143645815483253919392848
Row 273658503394213558862463524953063606242226718215954230232141777766661273918822233482340652035279048248335029535051912943262320575211915575013541599503616352105432251453743218348714225532417
Row 2824743902536166331627243647271947861014812623532486026921121229028855926225361431514706859211930371062163947155523350223126112383331233727341504784567316621303742246942853587532429181341
Row 294093262159453230132745843060479949857173838379527042881418444302231889413430263331210428404021542617243310803570361440116461934190669942513411178436982711923450270928895274347578328733175
Row 3012695112506330103686231091366842582431241133539312029530383877728152696773475135841960489149247551346283230332792586216154265302325447664072265130291019343326677035208378152863336454638
Row 31429615492784106313841043027507119418474449126450431735488141211145014488215262005250235482137852338494022421195371356431384779229927403581323321211502324910613771842405546041214437082162
Row 32140838853740559465475511623621280440329522146465813159560275548952501524613752069664271130367524162894389511829031282347231763042668543040129166624007122398348759251792256838361592
Row 332903503355361833531427602911597052145014636501530463021119068644854296323325152339543534142167404124213453436403515370411032489323442171669303726201026173828574794488936872604210323127435905
Row 34417728962947499729103409255940001124163929452178142810144256540657855439454252052840414611494721405542993341375239981338151837357132743944440610595547417546750693809212535383079568417392682100
Row 351132417932412463189935771514492214866123507302859304560572445515282643380838942132571525535803214211625992634854473949720401426526311162397740434921372672250720802975463544255018535506
Row 36257821524025362591205952855440172354565794447755791198539115025372149748234527580145043121567910545142593129289687952164912703329568810123188363373033122786129719823379589134432823876
Row 3745351754328742045867579034331789118239041425416329118102161207759153488300529664181513748905002314846369653384903458720501596370456618355139358841618517787446933911536546492719589137763502
Row 38339017614849439346753342518710835982537475940112683281646793181429328372278274852732653547364818341663588927764068283837493913321521017835933183150043953429607537399027668465373541224331844
Row 3925894513324719624857314156832722417115159834070291744951727230848314946474651595509522918601247201852232542947503438636004887498744373447414365337256256593697963487679310571413304985066
Row 4048681809895372195508443076711358562080895444204014238328059942281287352943903435146715534435063565439462129501381372538435532580483737013265118231055358442919456953579565743939322819
Row 41226317023045111421763437256933139502919348143961801274134405933276711414196282444397705745143504831166665535208449202709170514325369557917347171317455294547215657187016125474239120368851090
Row 42107650384680321348415043873711321531140083628581812223380238142827284265201517961406385553447063449751412901155094349174148353284524525988720199344244353180510973693956484627261270953
Row 4372440873924346233343591539445878622325654847501031582161426467330323613165304318883447326157143946584450713223326433962319521522433802146555658585995374576227221426229239772844399734562342
Row 4418336045162635392358931057473316245417210731483593111931681379485455012341196088737799234308359918467240541339671224912181955409199678353553457418037455880342213184252342209048591073804
Row 453241321151604741240533930884405578944615448498022518218892092548749375407474915163481441092578119640314989458534536597835861548501839111224238553945843269373733592412193343626207313342
Row 469322719495913301281342142182481205342813884320841552144566819501446491055342863390134278622647556084964413036015184275716585269244225515965298441994237418950728553014403462947927862686
Row 4728934561869469216135001864503919562120297636363439188257222684773347630473045431517401540395361848375335411388841382855540149203655251710431264153597455523095467119552266303529539711329109
Row 4855011079572611725504656198739088943973586460155083768662527623155595397557911223526710363300352039094955416131055961177431657024905247179610614600573726835123087132444031045951308024963895
Row 495261279959973076325044322367173356549412402175954254997364431354102881322034343115263616171222432939845180569852104860430237934231349858216663375450833813410494744393546333918511176341442064042

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.