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 04460463125854359583520734359329215711605146717792919464123663826374485024457403136423431632504818503611423515247335513743244615933842487732925615240040593504585251214774321531101084566535112806
Row 11910334215982081999205941691242103120385984147212073115326745581440158452335534407613921140271953284400753993725600524534046110073646234737882707552457062719299250997211316229933906464698
Row 247353422221432205975152031723032342813391707586245231794345417394892182816354783335047431556586726045164525012494418566543902721316553686141954121038795323100042812215154773314127294381634366
Row 324173132112129935814376157322583454539575719256135905253266852264612180450851835574842114456262511295233310015818545314072141137815659279378255622663665626515684587750938674072309242553896
Row 44952998512811215769361430115895192343204818286265955201094243547324797315227855807307412541035575612741897284856921866456018894843157301915992392345126381616584607250987153792919577526663321
Row 511102181207138202438190026833635266327731012052597024321268365494951242119120560047211463283280337038904579392046641607475241513419273158329581613351835324860433086649994620433322261853709
Row 65891004153673641572020373375145531937305151722952168180515761593328622944483117940063363178035224559556132442985493506139223401373325123926236150533706290491950534109919215725256718125538
Row 752991022435222316431183322713035890265299722645461445417515271314840274668271862355421177365158305614171084520249322627209356648694160357847944140574131714847375014924068273557115231270929
Row 85104462111614023485685647893582478741523830317269720145304247114824352731932528053542570594433341283426542573622125110321995968542225431412397286345044009500667855832400954495653733741987
Row 9189450374761896195121804445759171338041175551732255776664218051542507456137068285159265852554139576857063292459050742315543487415654646554529063690354685618793297360826551199495540714791771
Row 10577851221623405537213448232439983952227160146261664507539232315224045848725397164542218231668317122931595071749204754652361275316659701552473135118414655362533965481934346458751659366237
Row 11256818622353926477555511761656396441464584301236169043523410587354967595339299937002225480547701576829891123538840113766153728611677418473166728945214865342138325853000560537407693465
Row 1211801173351778572843383884235751335029553318861934280738252664437122732425137310765517412648288423629035563254494342154843121594450142450356848055769502148582258186141025242482328692247193
Row 13187542524776390423642219377026682497205810983824161511047701111467558204696503153864717563924125866218551628173954293501166566055925561103746262858526025344411293514536502810406335854271867
Row 14566058704972198250433645811396419892201308342091579440214633752300457842624167235029905596582051001063398923453611142346154503158919673305561788740398121535113325801924230231794920185950002020
Row 15314594110131532084295612362466310216275126994233590435958686134919237850771179244423676112075362128535116931126952734122275944655665364014402812192941502813513215375159092288137840703783
Row 165508525449135935710403634722931801502628845531555322223804234526451495876294636193850513645256958585227282209811191917575635657622514513436256633254894594538611364436529291575370223104557
Row 1745475764107519253504895438397018147469974071573344835673427132312922072390485419232111143153483827520181406537544369822867531822830052443842485008246718832398517550712730455025488
Row 18108744831023582526343246260841775848230625513121964534933638075224345372233454007310157205693199445422619795651173733371652502430242952475862681121648091303406012645439015764365734011600
Row 19447437412265193362554682733248037345949376124843156408212430663214403513043802223136958962310329856342469286220174751489589046585892588394243872305266444585357428551745104896216441911895175
Row 202356463725167649483238522558147788369471267558916125899379614334322500247857765172709528735053485579316982674417514465384139225075797416870641725585195559522764690128226354037265020255883
Row 21549650271198280477044641112902295141037253222376916316457993905289958371361376655173473407919133053453188032261761202651657764069276112065951911411132424549375169844413829245246051743356
Row 221937530498836730152465212169192526886042313904592786276452373316314874184564512932420300539623176779053760333117223891825452481311284407487459147041847109722843650137186410403977
Row 235121461278119015120313505524599721266338851279246413786165255023589896237817334938817703126205619799215781110840873773498538824683073266149151634505434931018258897944421624746554945
Row 245485193404939852455315654763985193960753812579589045108219733643601963725397149648145804317550213964370141331585850178449450904793462082526593173326935752000414854115519727260623862693
Row 2511631299271348541426996337831804363150105027120641774462210018802262274645892192136975014299192049583451254904354152871555495418319555905841250113273680255628503997341487849544423320628
Row 26334329845252591960353591163256753585233425632044126411643142542501232774192114127774218527542720241516512221652011729432416811975382750215614287198059273866248960561657942924837275959772468
Row 274148576468015573174590219625523325964157288452294706219334555570499913703472169110343160308220821741964338756765915370489628665231187236074035360723865174266762455829141385419661563347
Row 285133038423552003357167145265216266318684252533449752833538932573771129744652512527734333079418519824276488154015442388706148451764126405543057223196557306791059965829128029504901416220511953
Row 29204814854042608571930154595228493456744689130113322982539375217232487597939573735112454991252973161149663791270141634618534645393933472249313087556023306244598211156255812173349499355512476
Row 302601471931465853516784702437846833133141233991290349901533834512422084543992529016693110504358773050410069229812124431544636513564149215065044839207033715704284722901339211436953815
Row 313346405425051042561959835399483579449073023165238386489767124542243865813488368326195440297381038878579241594820232123115654365755925997173125512525507605305496642024448112729784580
Row 3249881982709549821254328468038002808345355044601112441183080490155241105037262902168911641306323247031703668655683778236750431334522453244878207558913834959307228412945513394238006972136
Row 334081219217523685766514857035582486998046541878241208733426950793267295346257465095502196312646554189572418451851528426491638842394345151792412139950204662581351869851259743694779326
Row 342168466648482735383552698963141279320238946552465520128795843147958095494444146314244243014373459320248745928224428482181095442359143325015292821872031264036284139306018455584198552171726
Row 351856358133748581439462202571710693507341523455850219950743235161159024317323283583745745690568646691209532338042285514012781400779268557058723825324558994904874576711991858285411191564460
Row 36256351651743541456255795559444933435887373827418513195985760290630752039162056539756249781452963263627054113153799330314965381626163455191439831120111201419372141295099247813472234727
Row 375532424215971881462739255131113800556540628052219402478013001563171853732185510453704641125016160057244635132343222395218211134057672084482119593194197261037238543339002315497693879
Row 38172842733111286280151824635179511345281900111642291411538739922881442655734307917215636133254443832364806810409637631834540898842775955319819533047655042483513714978136028005572284528172823
Row 391738104373254151625735334352502854297032471215588451704223509815241805148150373640912247229038044727428811144538385941034457228418903860546318757097725410414054075766241571434314032708439
Row 404793398610544985258547431482565641243109482958790421219033555319219244104575636311095548449007125406475053043177294046613583138317915433911434332692966761345142811563379447982687239013095988
Row 415811431221225094319728915084476684622283969974506716932983331426451863750593754621793611819285355373607443643371721487236784823209649162224061400157840235188293324034736432127446023775777
Row 4229475391420249919036465293403319835040839491110371300206985634582709551176749372519207741104747796217141075683414958423760392650252647481712033045310133251969362632559243532166424258135279
Row 431518249445265880483621174939161815297125913835910233053112305178914263711190527064765117434742677157142873325110752213393151445990364510336417743894253521918693351547547334727272957743202
Row 4452182747663992595532115802520753309037201149269535511864348424120872214314370534621298100131801354222653925514850264254017701851672586042355585159876359534028167359381927273712192969900
Row 45535342901285459047621968611723210817325495277248795633311340536275538206960279176550815146724122545274574245842952275590941993185911337326881281437115422719221136843120322287117682134814
Row 46272944284127117535813441641532988219617768771813552018212545333744257822062853748425741734140483236594503446926444560510194135614735285147030574379413443651864160623322156545338925572515
Row 471420262246642909157211951972795418360950841585668207631532933209352815944495133521775754378159964385200120652911295737277525706123353985693181998541464583457464710188613932575543830215618
Row 487661489262032661510387832294353127422461793263771957663729507341872450575934121667402335866615482270129515820536745481552319945215914161146712020156021913344332627721884341521672595362818125868
Row 492852033481411294724107649109654751514437768225437520829412719387927485866469119855126969327722061995504521131658131128477820031381190630261530105715315743155922101858227933664873339824103633

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.