Notes

  • In v2.18.4, added a Magnific popup example to this page. Note Please take note of the extra css needed to keep the sticky header aligned.
  • In v2.18.0,
    • Nested tables with sticky headers now stack properly. See the new example added to the bottom of this demo page.
    • Added stickyHeaders_xScroll and stickyHeaders_yScroll widget options.
    • Any defined onRenderHeader function is now executed on the cloned sticky header table cells; the onRenderTemplate function is not! See the change log section for more details.

  • Note To access the added sticky table content from your code without worrying about using the ID, you can use table.config.widgetOptions.$sticky.
  • Note Add the class name sticky-false to any header rows you don't want to become sticky (v2.1.18).

  • You will need to modify the headerTemplate option to include the jQuery UI icon! See the example in the code (v2.7).
  • Scroll down the page to see the headers stick. Then sort the columns using the sticky headers!
  • Multiple rows in the header, including the filter row, will become sticky.
  • As of tablesorter version 2.9+, this widget can no longer be applied to versions of tablesorter prior to version 2.8.
  • Because of the limitations of Internet Explorer version 7 and older, this widget will not work.

Options

stickyHeaders widget defaults (added inside of tablesorter widgetOptions)

TIP! Click on the link in the function column to reveal full details (or toggle|show|hide all) or double click to update the browser location.
OptionDefaultDescription
'' Include any extra class name to be added to the sticky header table (v2.1; v2.18.0)

Note prior to v2.18.0, this class was applied to the sticky table thead; after v2.18.0, the thead and caption are wrapped in a div that is made sticky, with this class name.

Modified in v2.11 so that "tablesorter-stickyHeader" class is always added and this option only adds additional classes.
stickyHeaders_offset 0 Set this to a number (in pixels) or jquery selector targeting the position:fixed element in which to place the sticky header below while scrolling.
'-sticky' If the original table has an ID, then the value from this option is added to the end of the cloned table to maintain a unique ID (v2.9).
  • It contains a suffix to add to any table id.
  • Its default value is -sticky
stickyHeaders_addResizeEvent true When true, the $.tablesorter.addHeaderResizeEvent function is applied to the table header cells so a "resize" event is triggered and the sticky headers widget can then properly resize the cloned table header cells to match the originals.
stickyHeaders_includeCaption true If false and a table caption exist, it won't be included in the sticky header.
stickyHeaders_zIndex 2 Adjust the zIndex of the stickyHeaders element as desired.
null Set this option as a jQuery selector or object where the sticky header will be attached (v2.14.4).
  • Setting this option with either a jQuery selector string (".wrapper") or jQuery object ($(".wrapper")).
  • This option contains the target to which the sticky header will attach - see the second example below.
true Scroll table top into view after filtering (v2.16.2)

This is needed when the user choses to filter the table which results in fewer rows than are currently visible in the browser viewport. So, the sticky header may still exist, but the table body may not be seen. Setting this option to true forces the original table header to scroll back into view.
null jQuery selector or object that will be used to monitor horizontal scroll position(v2.18.0)

Defaults: xScroll > attachTo > window

Indicate the element (jQuery selector or obect) in which to monitor for changes in scroll position; If undefined (null by default), the window is monitored.
null jQuery selector or object that will be used to monitor vertical scroll position (v2.18.0)

Defaults: yScroll > attachTo > window

Indicate the element (jQuery selector or obect) in which to monitor for changes in scroll position; If undefined (null by default), the window is monitored.

Change log

  • v2.18.0:
    • Nested tables with sticky headers now stack properly. See the new example added to the bottom of this demo page.
    • Added stickyHeaders_xScroll and stickyHeaders_yScroll options to indicate the element (jQuery selector or obect) in which to monitor for changes in scroll position; If undefined (null by default), the window is monitored.
    • Any defined onRenderHeader function is now executed on the cloned sticky header table cells. There are now 3 parameters available to this function:
      • index - header cell index; this is not the column index!
      • config - the table.config settings for the table.
      • $table - the target of this parameter changes:
        • For the original table header cells, this parameter is a jQuery object pointing to the original table; this table has the class name hasStickyHeaders.
        • When the sticky table header cells are processed, this parameter is a jQuery object pointing to a copy of the table that is used as a sticky header; this table has the class name containsStickyHeaders.
      Note Any defined onRenderTemplate function is not called on the sticky header because it is a clone of the already rendered header cell; instead use onRenderHeader to attach event listeners, etc.
    • Removed jQuery UI theme from the theme selector in this demo to accomodate adding the accordion. With the current setup, changing the table theme would continue to show the jQuery UI class names on the table (uitheme is not removed when switching themes), so the tables became a chimera of jQuery UI and the selected theme, and the accordion would become un-styled; it was a real mess.

  • v2.14.4: Added cssStickyHeaders_attachTo option (default set to null).
    • Setting this option with either a jQuery selector string (".wrapper") or jQuery object ($(".wrapper")).
    • This option contains the target to which the sticky header will attach - see the second example below.
  • v2.9:
    • As of tablesorter version 2.9+, this widget can no longer be applied to versions of tablesorter prior to version 2.8.
    • Added a widget option named stickyHeaders_cloneId
      • It contains a suffix to add to any table id.
      • Its default value is -sticky
    • Table captions and any additional rows (filter widget row) will also be included in the sticky header.
  • v2.7: You will need to modify the headerTemplate option to include the jQuery UI icon! See the example in the code.
  • v2.1.18: Add the class name sticky-false to any header rows you don't want to become sticky.
  • v2.1.17: Multiple rows in the header will become sticky.
  • v2.1 (updated v2.11): Added a widget option named stickyHeaders option which contains the css class name applied to the actual sticky header. Modified in v2.11 so that "tablesorter-stickyHeader" class is always added and this option only adds additional classes.

CSS


	

Javascript


	

Demo

Choose Theme:

Include Caption:

Sticky headers in a popup window

Attach sticky header to browser window

Student Grades
NameMajorSexEnglishJapaneseCalculusGeometry
NameMajorSexEnglishJapaneseCalculusGeometry
Student01Languagesmale80707580
Student02Mathematicsmale908810090
Student03Languagesfemale85958085
Student04Languagesmale6055100100
Student05Languagesfemale68809580
Student06Mathematicsmale1009910090
Student07Mathematicsmale85689090
Student08Languagesmale100909085
Student09Mathematicsmale80506575
Student10Languagesmale8510010090
Student11Languagesmale8685100100
Student12Mathematicsfemale100757085
Student13Languagesfemale1008010090
Student14Languagesfemale50455590
Student15Languagesmale953510090
Student16Languagesfemale100503070
Student17Languagesfemale801005565
Student18Mathematicsmale30495575
Student19Languagesmale68908870
Student20Mathematicsmale40454080
Student21Languagesmale5045100100
Student22Mathematicsmale1009910090
Student23Languagesfemale85808080
student23Mathematicsmale8277079
student24Languagesfemale100911382
student25Mathematicsmale22968253
student26Languagesfemale37295659
student27Mathematicsmale86826923
student28Languagesfemale4425431
student29Mathematicsmale77472238
student30Languagesfemale19352310
student31Mathematicsmale90271750
student32Languagesfemale60753338
student33Mathematicsmale4313715
student34Languagesfemale77978144
student35Mathematicsmale5815195
student36Languagesfemale70617094
student37Mathematicsmale6036184
student38Languagesfemale6339011
student39Mathematicsmale50463238
student40Languagesfemale5175253
student41Mathematicsmale43342878
student42Languagesfemale11896095
student43Mathematicsmale48921888
student44Languagesfemale8225973
student45Mathematicsmale91733739
student46Languagesfemale481210
student47Mathematicsmale8910611
student48Languagesfemale90322118
student49Mathematicsmale42494972
student50Languagesfemale56376754

Attach sticky header to its parent

Student Grades
Account #First NameLast NameAgeTotalDiscountDiff
A43PeterParker289.9920.3%+3
A255JohnHood3319.9925.1%-7
A33ClarkKent1815.4944.2%-13
A11BruceAlmighty45153.1944%+19
A102BruceEvans56153.1923%+9
A23MikePeters225.6920.3%+2
A55LeslieKent3315.9925.1%-3
A3FrankMint4412.5944.2%-12
A21JoeThomas4515.2544%+12
A12TessEvans6613.5923%+4
A21PeterDunn122.9921.1%+2
A33HarryJones1319.4922.2%-6
A13JohnJames1613.8942.1%-13
A71NickParker4513.8944%+29
A21CharlesDunn1915.4922%+3

Nested sticky header tables

Main table header
Main table - row 1
Main table - row 2
Header for the nested table 1
Second header row for nested table 1
data in the nested table 1 - row 1
data in the nested table 1 - row 2
data in the nested table 1 - row 3
data in the nested table 1 - row 4
data in the nested table 1 - row 5
Nested table 2 caption
Header for the nested table 2
Second header row for nested table 2
data in the nested table 2 - row 1
data in the nested table 2 - row 2
data in the nested table 2 - row 3
data in the nested table 2 - row 4
data in the nested table 2 - row 5
data in the nested table 2 - row 6
data in the nested table 2 - row 7
data in the nested table 2 - row 8
data in the nested table 2 - row 9
data in the nested table 2 - row 10
data in the nested table 2 - row 11
data in the nested table 2 - row 12
data in the nested table 2 - row 13
data in the nested table 2 - row 14
data in the nested table 2 - row 15
data in the nested table 2 - row 16
data in the nested table 2 - row 17
data in the nested table 2 - row 18
data in the nested table 2 - row 19
data in the nested table 2 - row 20
data in the nested table 1 - row 6
data in the nested table 1 - row 7
data in the nested table 1 - row 8
data in the nested table 1 - row 9
data in the nested table 1 - row 10
data in the nested table 1 - row 11
data in the nested table 1 - row 12
data in the nested table 1 - row 13
data in the nested table 1 - row 14
data in the nested table 1 - row 15
data in the nested table 1 - row 16
data in the nested table 1 - row 17
data in the nested table 1 - row 18
data in the nested table 1 - row 19
data in the nested table 1 - row 20
Main table - row 3
Nested table 3 caption
Header for the nested table 3
data in the nested table 3 - row 1
data in the nested table 3 - row 2
data in the nested table 3 - row 3
data in the nested table 3 - row 4
data in the nested table 3 - row 5
data in the nested table 3 - row 6
data in the nested table 3 - row 7
data in the nested table 3 - row 8
data in the nested table 3 - row 9
data in the nested table 3 - row 10
data in the nested table 3 - row 11
data in the nested table 3 - row 12
data in the nested table 3 - row 13
data in the nested table 3 - row 14
data in the nested table 3 - row 15
data in the nested table 3 - row 16
data in the nested table 3 - row 17
data in the nested table 3 - row 18
data in the nested table 3 - row 19
data in the nested table 3 - row 20
Main table - row 4

Next up: Zebra stripe widget ››