Stuck on the website you're trying to build?
Learn how to solve the problem with my 1:1 website coaching support,
or simply make the problem disappear by having me do it for you.
Overflow scrolling The table is inside of a container with overflow:auto
Window scrolling Header becomes locked at the top of the page as user scrolls down
Responsive scrolling Hybrid of above. At some screen sizes horizontal scrolling happens within a container, vertical scrolling within the window
Window scrolling
is the default. Initialize floatThead without any params to use it.
Overflow scrolling
You must specify a container element inside of which the table will scroll.
This element must already exist in the DOM and wrap the table
Responsive window scrolling
You must specify a responsive container element within which the table will scroll horizontally at some screen sizes.
A good example of this type of a container is bootstrap3's responsive-table helper.
This plugin supports perfect-scrollbar, if you want fancy stylable scrollbars.
Options
Note:
All the options which are functions take a single argument: $table - the table on which floatThead was initialized. ex: function($table){ ... }
Name
type
default
description
position
string
'auto'
Valid values: 'auto', 'fixed', 'absolute'. Position the floated header using absolute or fixed positioning mode (auto picks best for your table scrolling type). Try switching modes if you encounter layout problems.
scrollContainer
function or true
null
Defines a container element inside of which the table scrolls vertically and/or horizontally. If boolean true is used, then we use the table's offsetParent.
responsiveContainer
function
null
Defines a responsive container element inside of which the table scrolls horizontally (at some resolutions), everything else behaves like window scrolling. This option cannot be used together with scrollContainer option. bootstrap3 example
This function returns the aria-label to use for every header cell in the real table. See example for more info.
headerCellSelector
string
tr:first>th:visible
Specifies the selector used to find header cells (in the table's thead element)
floatTableClass
string
floatThead-table
This class is added to the table element after you run floatThead on it
floatContainerClass
string
floatThead-container
This class is added to the container div inside of which your thead will spend time floating
top
number or function
0
Offset from the top of the window where the floating header will 'stick' when scrolling down
bottom
number or function
0
Offset from the bottom of the window where the floating header will 'stick' when scrolling down
zIndex
number
1001
z-index of the floating header
debug
boolean
false
Point out various possible issues via console.log if it is available
getSizingRow
function
undefined
Used by IE Only
If your table's first visible row (tbody tr:visible:first>*) contains td or th elements with colspans, then you need to return another set of cells which have no colspans. In other words the selector should return the same number of cells as columns in your table. In depth docs
copyTableClass
boolean
true
Should the table's class attribute be copied to the floated table? This make the styles written for the table's class selector apply also to the floated header. However, if you are later selecting this table by class you may be surprised to find 2 tables.
autoReflow
boolean
false
Experimental
use MutationObserver (on good browsers) to reflow automatically when internal table DOM changes, or DOM within scrollContainer
Methods
.floatThead('destroy')
Removes the widget from the table, returns a function to reinit the plugin with original options
.floatThead('reflow')
Cause header to realign itself to the correct position. Same as the reflow event below.
.floatThead('getRowGroups')
Returns the table's thead, tbody and tfoot elements.
Useful because you cannot simply select thead if the table's header is currently being floated.
For more info on why you may want this read through this example
Events Consumed
reflow
$table.trigger('reflow')
Trigger this on a table (post plugin init) to force the plugin to re-align the floated header. You will need to do this if you
enbiggen or ensmallen any column widths via DOM modifications, add/remove columns or change the table's location in the DOM
while using the position:'fixed' option.
The plugin will trigger this event on the table when the header is floated and unfloated. The 2nd and 3rd params in the method are of interest to you. As shown below, be certain to add your event handlers before calling `.floatThead()`, or your code may miss `floatThead` events.
The plugin will trigger this event on the table after every reflow. It can be useful to know when the plugin is done with its header re-layout.
At least one reflow is guaranteed on init, but others will follow. Note that these conditions may generate multiple reflow events.
It may be wise to debounce the event handler.
Reflow will happen on:
Plugin init
$(window).on('load') (for tables with images)
$(window).on('resize')
Sort, filter or paginate within a datatable
Manually trigger the reflow event or call the reflow method on the table
Switch to a bootstrap 3 or jQueryUI tab containing $table
With autoReflow option enabled, modify the table DOM
Examples
Overflow Scrolling
Overflow scrolling is used when the table is inside of a container smaller than itself with overflow:auto.
This also demonstrates the reflow method. When a DOM modification causes the table's location to change, you must call this method on the table.
There might be some table controls here or something.. Click to remove
Window Scrolling
Window scrolling is used when you have a large table that takes up the whole screen.
Open Issues
Issues are pulled from githubThere are a bunch of closed issues!
Common Problems
Can't get the plugin to work on your site?
Take a look at this list of things that will cause the plugin to not work:
Ideal HTML structure