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 033621358212493163227413255247851584960130407153815773496335341492696579610203565945334529641905966584135961177184151315409380834414999198121042891941630184935892263477624451080599225585361
Row 1987124143542239221454924918215549293752159582949063818149452383829527645475546478730605551402447913558722753533509230193195334040398484534972147849853359422407443829754065765138930215915
Row 22223261131419703281175034161015582315712671988189942123582541115693411214720404761381182303283857294076536338671693314049262075340447901904752473562029053220259314054870100557469018321846
Row 32063222902473943593730556649193514154347792907410818714574137539583250548362930438094278138443713121574956624134265424012521756177914945764204916144238226943558192629200718032513546117734416
Row 4190748535493124629472902568209348025212958723298942751560429541655311091343059174078528564943365333206340132218744470420543104259579831095575392245984481113556451504322315072539465956275652
Row 5501546411154293931142241222373608475317565172162444333426671541337729795382552101275036032950490743831445588836842995345517432063745304315793875261226621292598881933410117942813801210
Row 62582534343117242111342570059637083568125052292599396950351276545191352430173108311226652591727448559885991319638671623192716724123300355931114527459691538283710235744138822245633318117222943
Row 7395610373413154500354983227167823241882406330391911105034031014448949793840300728662329462786824211487561818064663422537605645277751375708418049112250458239459684903348242195176482545340794742
Row 8559281489959263067323041172470119693542731850280618615909569723281176229841282773901569339655295705446136774012897301169058002641272374624721893132755552141044245013773826617354143475949
Row 944373492504509720401540363238162702226042123845448531111740296141255441898212491044403508218159385594628652251960177526093425129723302647241643752821275433615395503429254593520440521611772
Row 10136579420204744274268603190438081827455455693133177017247291465357532303954447851213508359446825734064059454292741591691021171522634175111435212177722172241335451835066478253191124
Row 111204446933711085190554201577586444862269375311372274319326364543359640704168515915526545820280754532181328822281713259164047871194507058616301793154737181231196916292715463313574728281735455050
Row 12361212495302588034735443188869067957664013506212837724233273781445925282644928386326973020291616332145249452932721438016123633604171273952324439222519164529555969154655668476731953436707
Row 13409062233093531350421315149144154100421301051137042835861346926017123462267067027243566367151154949171614315521670550435491120539458601064102144362396116231239292519380948622671518746763989
Row 142141508214453662439512645375736392179218293816149447094859519848582961303924994145348251274901932419237412921037472806160550914736559126994236248687027153169395228228314022396129501309836
Row 152309540229342182545655985430231947616662303119572413704819290841129732407497233055342978292457474554186501022334727238643334179195324933443464307545063296321224051820735958394529494629443
Row 164329288733724704212216621533766401040275929109019441122270024103210323022118238581722419953153950132012152305142141020322982484438582103511344250721404182411840262000246633195451437689568
Row 172506723142777322228378101158412225532582864442240844233799355592177456969236240053202212629175845347836352371359844102371576568018314315644210129725291342338528862184428825132965104
Row 1851883120141436169417411517257715834018361155361389289639314359381121883264411527696817850514175426543500315245850428433354720102743722921986919505323734142232450658909554256406322184181
Row 19303249035788444614745930326731835404937158145241225614214422310167220744205293138131590549620529382733505715343351317727723469253521003875915259759665901808581256426241643164289338305989
Row 202806705502343147032540592544331724416938675699439032032905176816233724443835522629401964318332974043563516623760177740266733380376983752685000501358772302255543791314509713194585275949942600
Row 21736381226383481354818632959595011169742013430234053205091588842522219326308978774866597759741620142031655845500561026375652243434755269119644421210373691830312843535136518535811775395
Row 2220003208267817121581393548552731434757925077477657033629531107411641438611676371597971130258185810554627205680559593613101517849212999315856691269173154354974397956652018552342673015179
Row 237841526615172131311230168203597384690343240062701377143315443505554134460237831871704437535653520151322212838374239111046501216164457129211003962389117620583328395011203390838514739644780
Row 2449671955131127222746498423774197576314623512194117865021873023318421492526336647261720856521752604242190454365326372113403773476936354158799437045393722327913451277543140622775487313871723380
Row 252980180415665570488027304345605888240541853048963175297177936724309212514352296963402454494515230647611321271137791676577257593392488342562713266151103844277360833318944234326128235942290
Row 26293952535785717153316462812827345489443361899335234021001433341238229942113533787458213403422551254463536022964372438144243001229418321321442605665708250327943970302241065718101733283054
Row 27293571619853098132658474751435349638252554322939304484202438015683064310127723895466337591957223939151530456545730211984229223051661473340531015547841544290193158769113743395172402
Row 286243088342453971395351410673790321148302061227636775820543244831274317326675773330823043505167535116503009183711301386356824083004297555734888835189020174244514446171406453233285297522756681210
Row 291017262239651558104525061775349437651038282814919479465266379484915271162559131249085297164713575701164557802517408222375589012366136958565124458233882840433013871694784450738679148702859
Row 302710238660329663607430837710355321437457165046492057615395173175644625315331226945602462313515326404511948683040494555675815716326217515526670569154611848403330623807138370335615943
Row 314753459952272012426577051750435278223322242351119784524982687298220855043168464314753475476552591135009360940536971710550530145534968489650941742894334045225013297528611285585512939451148
Row 325512276756631740593353902590240756841541211126833658474856325372032769251541035319475541236345004121199445322535211129130135056386622382920420252853026517164643492516495323311531398021241286
Row 33366119851923386139939912721225845284832601624434145101535309214593763402812036303565335526971679560119349665038217938604298191636253164438856352102267497822404767141323995129273530636002883
Row 342928514048613217215548622208363115732684448245651847153564573534731136743356034403371353347933833445233841211776294206432548415269194239011642468151092620491241464860328820725034155116001974
Row 3529543295459847275330091137593433220884433132982685553833255576271236805618242779431119576741175881374448921941840253230840875268175940593735381046085012419446203506938246724675191696
Row 36217039033037176721684398244625658354364456499631341532169971856346831956952678316548115713259250743885632478452645466483013250734374356431029294502175632652896343139411622223490643414665
Row 37486340333502602501022094396343845123502380536295973488733985609224241408155270616397449967538118992235618190116647518674993379331947305316240333183903150717941725223821654343073390157
Row 381449575430857901909531015019362205738294455671026494341198111223303352833464777488621581258233752023892472051315347439732045476445939814304229850044711397451844583528222758115486545816562163
Row 394370138541414483504111230652371602211525252053709129153756275455977387616261815584013301671128639132786289834351313149156203566447537321024571510728864245125649647135629865778576733144178
Row 401145295511555541297201917314961623215420463279258630234969432731721571291859733351982212031641245587834333261350125123453115118733813279831881030578458634994589223340473230244364843524552
Row 4121272300137212191130261781407222912511351929712472211421391486396279953628194118841486343787193634223589125704614137642227043321912453245352571476923991096792581554245833372312936233226
Row 4250434994488471032725145771152630933209013218227011692188500143414537405355611528587945331873500432004675565051294161373838424161117551414032873321893716362198255281154772924248530802467523
Row 431543260394323744851423124619383722341271468233946705854790187244425922441451587052154403108455134459804039223039201379201029647543213148711755497319253905769490738145125245185542502202
Row 44102141025185345361257211142275220334175732564242941692496571941982637541724923526575518805753411455122755478272528151636535941228590942201091171357232567121667553787215945411484953261074
Row 453486915170284653434846440419715643827273934825385234450547120489943023972058123069051559183562423889613141650438732171535254436327865836112011553766553235123865380592746670546584
Row 465563310239110471108397354803471420747042648182530873746449344406572506641595362154422861505234319705308381949861700376129618044234271048993914110375716265487458730609113971430329929183178
Row 474122270046401665364265297440233064743234437417295094228510534587283221618573370313710594717145046022158531442707226140627926461356403316504213403537478353167235099219924355498828924860
Row 4832824224458642087320443134453339653017296057084411444353334791365424117431077184633457913404601626337830641413342552575145267155343995421418035798206324844765809146020313968564291446235809
Row 494656193650874728581948515821231651212612368284993554805189549948588327550981769286844120159913195371341885674729506882647846461631122266540181862369511803670284112075787528646373681828

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.