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 018264635235734024493307237535527952923489238453593908200436897803857245139245081740276470149565671221517431095519476887246753264241724304301129131215963159516617428266714303530119375855
Row 116228318463945205264217591118122542425289556218429018815812365438902741609461342549124649974588347201372285456020855605523420692917435659141224534825139953262075144036334472264016762829
Row 21829559842328415124588634404880206853713198530935101641569806529231511970525057821285658940355219825504249595126452742394558523271457819219334261576565040885547847401788493405718052968
Row 350724741508841087735171464016276652125901378457771642284157381256402403415761828633399752471716661172857624944943146318605442356211963912263627994404352230624212175383629831724329140243801
Row 4327347031670479726212875460532728982366480118924837595448440150435995312538332241437258032993684565021365470224814119245323966192048595420841369220016175150133135863670345651924114605368
Row 52209165943423873546919483420233203317762615378797824607501887457533598827582428158492739731698407552580841379823787236524247565739570020815876327320341275218355252822071575326026493820
Row 616213507184240915167999279927431001998280214539211699119728551625466717052214870586616124656425637672597465236301030320691331073810155543265382271316381805538741933189270055512589405110505124
Row 7139020877583458564035051032636370641676199364827838751712181854973850255269614194352844556530455010428536564454565630792150977150930272646351528935919403641685354547125931686395127822856
Row 8321539832581362628514177427738144617548117473915409233522985641154855735061523519972110565841235410148922862208360336722128422365920715945264394249092699298233681941376823752285342273512954
Row 9205951217643775886489112404258314428493564552537803517363545724607494127721566112130835147742541400413873542195623141071086983851223636751444118926654799193811674284575928145747309923411659
Row 105936242442793815364319333764246561533115445772027124813233388452015584197359542002494208026476193943372322425815483604107137178031798822490286566241703288476418647195442429395153594537
Row 1138603109393333895046223786153044333829103398421716933040300548483823290616733950281532511730354735161309588731741204194530714922335751485721826413018452568424247073113204317244219543658004719
Row 1217583693517354553480315717283273572751074282529939333906105828571542277713954155463166819269521616182245265395952519262958222150311173527563148492572794450363255235125622113699362148463417
Row 1331112542285236757036415877191348874982215758303626402850184117406924705977346719812698371627431493149918912385489318371769388115864749285314282856235841665882479463517885232609107527251445
Row 1419133204394337915658102895556434314539202333572771664274643665910422716124355217444143746502680341895909331421033823911934745488255084765537452222583225195488272441373151679562431785072
Row 1590735872677272220653410504049931683488040295830203627001812427436224577429321994745313144940851700959991244925184004141017145728799561325002188301712693964557934545326129432063848379623674058
Row 1636259342795007776551758521086239327425825319137131254783802169510053136475625388136605736925586655484157513214974893218727803491326013195445241469251065399983333624975970146655341575221
Row 1736373930269422135459258352114796380655255070579253482589170433344321285205032172410442124446125376152027493005384338194494528748714637782151410914492990247650293374256545227155680581328822862
Row 187221820481255061927355853124577456942161450203733911275139564750831662590014159832178329448072884608162319005304355313181117594274349732027412711342624448840411062254667456302541426052745373
Row 19988302051262925848156710111216775226122425824733465038075387107543010388423304424021288131027742793183527134796223840065908104216021936575956554445132542143921478186936261809560211695079
Row 2031531713356939701555168955802421565991419755124102855362886212827331985349122055942009252179239719111293349021565014519773013669722747344135828001288133611362242295486445691794351239295964
Row 2150732281479343805337321911472898272946444955242748073697586427922053242950101983713550513582420475623955203625462554273444023986212138713175157430481706307920262719254127825819362115744553023
Row 22466533151453325729552508155453285057111097722051619599953132355368310413396548553151974712627194541661028794318587251495102145446255061681598925751123486292451921368542632683486458021021248
Row 2325845934308948705820599795054655847812429055744085879291331741354390348748722149280221763978576138373455507855725847102718575470273150445463129326421491366427212982590329954392558551112144666
Row 24186554783943422629001467194529075322211143102514885510381468519459603165557153928783270402131505581167059844454218649694301550326842192089587322413748119619375750318529551352956395425343636
Row 25165340845985369486154344887554031983446493430923107220724011819234256284607469114560145695642422102047581280242183656362025823179130861719179921481285122460927823511582242039234583545808
Row 26381451926312990367716012790517454935925473548645246381231575947230826195500154523845323134367830913804901520449845079561111525993447234173818947535592325041957905814172412664905588834311408
Row 273842332649395116425968414516578457422765362236136048874618499519513352397495216474230289256762276558759796087434081423128914878332516675249773621124566468630073811391312208542465317
Row 28524925114327563943545574498146064104308854274111796295855815092137563941123785267146944953154724792041140436812846568422052578439719510175279235930451798210200636275234187620443040155846034898
Row 29353823435624092501321972319243741273529443086284958024354358030654089114236913335692319281153847255362836369655165565329141975431524025704411247038248939152977141217923229344753741588
Row 306183234580442913347396039892805787293219735733889233719071913358420108874596572949572576504326292773191158062672473917025465106438131856550383830522070163435941745272042003784422549151765
Row 314516340334637068245860421843822240441626801665477013692616148342864865267226319214594451058521354338136340724846188523004602551720841571030303317269665743492445121313307554261528236237582614
Row 3218475411472483759477623004981213924513752436296034435203784384438685491188522751603406111531223515593210213616528888912815291701236213203134437059875359191542561102263546391578104747912710
Row 334946573520018113472301245021669385440331825202817203855352852431615246719546210214216923725440255198302058261265439971540400914824137525131728833589368027293900441028473424947265117173138
Row 341158293389722282965227477731302432332650284525444333773718908154449992618134018955152750565025314717385356365308204820265387240149844543285112984123252538305827532311163335708264446043994007
Row 3513253130961480559255111855134999376347762436258329542338460851422334562814223512924673089389336009292986274439193931621411841015153369456930991139335654183481433528783443228437972958221
Row 36161846022230815435277115240371142264015065462177818785844286149414348345943353310535246304912391651162083205738211257186915053863187294219993420283745991876292619185723852776149247955992750
Row 3713886855350229830205706372557729952961172644924424397208035163216189224123404246342530203994376820942723200331911323013961104458309113306443716805492646110713391822169280759563834231365
Row 384445454318574128766394449656844362315255769705483348585715521634299543242519965846130538222402304929534233406657495884030979179250185216508552862602575351563957612163616333913317232573963
Row 395974464314321179481856119021512350100736919823004492919791744274225363276182650333759285811663038327715128644378496246751265539020791421247458411950375261742201151131714244586166035601556
Row 4031331155337227732708991593234804224173354934124460011411742135632291548480413316322404215518131163139561430162594369518209357559623877192554444343562210137234679634519612434582781727789
Row 41253340354693329842617195202904313018797093823415537122397200551913981485230342437131527741964314622982441193367504736471624556711026433373471454603117318847702702809988347279316162617
Row 424224465624257745712052921182474744421289409810521795357356125638545015381332479375612231177119758985191346131885610469415911382073405439574879392646723512922158530325518215917743179334124
Row 43482426693670302853020141103154285245535506321829993494421130894142442563841151769427727774836504434174865411644053725171512501267220436008794300235628620954764126514762690430442413017473290
Row 44287192558261091593236753916942668452216722555126530082988763452451575730305252277826714788204126125535324165947722535289358858775787292537282123620982219215422903548393385435904850
Row 451623526886457312748397822103195547328365110251218255920395248935304394194486642884675140751442276488716782903101110243976447784727914131175628293091748533752484566224638394824518818014062945
Row 46136736264871554427355545308391822411256583330544945132515837256947235106462837812183536837556062171403196375236463738045363027210726553893520820765440209697477949251214558750466191104
Row 47343142153331348950234060403525482726955305682745703789147839321329176395456322400218902933356324874081451845995011130050851036548730565315112036532526529538241081550750774885255042607111119
Row 485388100059673967307116225898217723177202598145814212827341624154402676134055974276125324238625667170146372483138457599254372311626974959200276591657092314879298543618841495391436153446
Row 4914097665717420150632813235223228932705775369299731562982321542091989132530993893377946074694755466556374664295453765348433713539249537682362714043419848615531120855253824228652013526536

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.