Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

floatthead

mkoryak60kMIT2.2.5TypeScript support: included

fixed table header plugin that works

locked header, floating header, fixed header, fixed table header, table, thead, fixed position, the cat is cute, floatThead, scrolling table, jQuery plugin

readme

jquery.floatThead

gif showing plugin in action

Documentation & Examples: http://mkoryak.github.io/floatThead/

Float the table header on scroll. No changes to your HTML/CSS are required, it just works. Supports floating the header while scrolling within the window or while scrolling within a container with overflow. Supports responsive tables.

Install

Package managers

npm install floatthead
bower install floatThead

Download code

Latest Release (zip)

Via CDN

https://cdnjs.com/libraries/floatthead/
https://www.jsdelivr.com/#!jquery.floatthead
https://unpkg.com/floatthead

<!-- Latest compiled and minified JavaScript -->
<script src="https://unpkg.com/floatthead"></script>
<script>
  $(() => $('table').floatThead());
</script>

For java people

Webjar

Wrappers

vuejs component by @tmlee

angularjs directive by @brandon-barker

yii2 framework wrapper by @bluezed

Why not just use position:sticky?


You probably should! This plugin was created years before that existed. There are still a few reasons why you might want to use this plugin:

  • Your code runs in the real world, where some browsers don't support position: sticky.
  • Any kind of non-standard scroll parent scenario, where the thing that you scroll with is not supported by position: sticky.
    • Your table's scroll parent isn't the body, but the body is what scrolls and you can't change this.
    • Your table scrolls horizontally within a container, but vertically within the page.
  • Your sticky top position is dynamic, or you want to know when the header becomes sticky and you don't want to write code to do this.
  • You don't want to learn these newfangled CSS things, you want a proven solution that works and uses jQuery, the greatest thing ever!

Things this plugin does:


  • In prod @ big corporations and opensource projects. Maintained. See open issues.
  • Works on tables within a scrollable container or whole window scrolling
  • Works with responsive table wrappers
  • Works with dynamically hidden/added/removed columns
  • Does not clone the thead - so your events stay bound
  • Does what position:fixed cannot do (and on browsers that do not support it)
  • Does not mess with your styles, and doesnt require any css (see fixed vs absolute position modes)
  • Works with border-collapse variants, weird margins, padding and borders
  • Works with libs like datatables, perfect-scrollbar, bootstrap3, and many more
  • Header can be floated with position:absolute which adds a wrapper, or position:fixed which does not. Both have their pros and cons. By default the best option is chosen based on your configuration

Things this plugin does NOT do:


  • Does not float the footer
  • Does not let you lock the first column like in excel
  • Safari and mobile safari are not supported. It might work, or it might not, depending on your markup and safari version.
  • RTL is not really supported - it might work in overflow scrolling mode, if you are lucky. Expects dir on html element.
  • Layout issues resulting from document zoom not being 100% are not supported.

Common Pitfalls

If you use css and html best practices, this plugin will work. If you are stuck in 1999, you better read the faq.

How to get help with the floatThead

All issues should be reported through github.

Requirements:

  • jQuery 1.8.x or better (1.9 compliant) (or jQuery 1.7.x and jQuery UI core)

Supported Browsers:

Change Log

see CHANGELOG.md

Who is using floatThead ?

Ctrl O

  • Ctrl O provides simple and innovative products to help an organization's business processes. Linkspace, its flagship product, helps share information between teams and individuals, in a simple and effective manner.

WheresTheGig.com

  • A free service for the musical community

Google

  • Internally, I happen to know...

tld-list.com

  • The first table you see.

Samsung

  • For the internet of things!

License

MIT

changelog

2.2.5

Fixed #487, a scroll container bug that existed since 2015 :)

2.2.3, 2.2.4

Typescript types were added and fixed

2.2.2

Fix jQuery 3+ warnings

2.2.1

Fix typescript defs

2.2.0

The Covid Release

bug fixes:

  • 454 - Fix destroy function when using autoReflow with multiple tables

new features:

  • 445 - Support hidden columns in tables that have an existing colgroup

  • 458 - TypeScript definitions

2.1.4

This release is dedicated to my cat. May he rest in catnip and meats.

new features:

  • Added ariaLabel function to the config object to give more flexibilty on the values the plugin uses. (doc site updated).

bug fixes:

  • 432 - Improve RTL support.

  • 440 - Aria label does not work with quotes.

2.1.3

Maintenance release.

bug fixes:

  • 409 - inf recursion printing on FireFox

  • 385 - bottom offset not respected in 'absolute' mode

  • 303 - scrollContainer with other content inside wrapper, header won't scroll out

  • 424 - table header fractional width set incorrectly.

2.1.2

Maintenance release.

bug fixes:

  • 363 - scroll container assigned incorrect width because of a jquery 3.2.0 bug

new features:

  • bad rtl support (only works with internal scrolling, not window scrolling)

2.1.1

I goofed, forgot to build dist last release.

  • Removed 'floatContainerOverflow' option, removed overflow-y:hidden css from scrollContainer.

2.1.0

  • 402 HUGE performance improvement if plugin used on multiple tables on the same page. Over 10x faster startup time

    on a page with 39 tables. Big props to @ineuwirth for finding this one!

On a side note, the last release was exactly one year ago. I didn't do this on purpose :)

new features:

  • 404 - Adding a 'floatContainerOverflow' option to govern floatContainer CSS

  • 402 - performance improvement with many tables on the same page

bug fixes:

  • 391 - Fix printing on firefox

  • 399 - Set header size on reflow

  • 361 - Works better on iPad Retina

2.0.2

  • fix issue with horizontal scrollbars + reflow breaking header position #345, #355

2.0.1

version skipped because of an npm snafu

2.0.0

Breaking changes:

  • slim version no longer provided. Will use underscore, or shim the things we need
  • removed allowing deprecated options from 1.3.x
  • moved development version into /src dir and no longer use grunt here

nothing big and exciting in version 2, just semvar and breaking changes.

bug fixes:

  • 348 - headers Stay stuck after reposition

  • commonjs support works now, i promise

1.4.5

  • 334 - fix memory leaks from print events

  • 335 - absolute position on overflow scrolling was broken if used with top option

  • added rudementary commonjs support to require jquery

1.4.4

  • 323 - use css transform (GPU) to float the header. (IE9+)

  • 325 - fix bug introduced in 1.4.3 which caused issues on lots of resizing

  • 327 - fix bug where reflowed event was being unbound after print

1.4.3

  • 316 - ie9 cant use matchmedia properly

  • 321 - do not require Content Security Policy (CSP) style-src 'unsafe-inline'

  • enableAria option has been removed. It is now always enabled.

1.4.2

bug fixes:

1.4.1

bug fixes:

1.4.0

new features:

bug fixes:

1.3.2

1.3.1

  • allow 'useAbsolutePositioning', 'scrollingTop' and 'scrollingBottom' to be used, but yell about it via console.error

1.3.0

  • renamed 'useAbsolutePositioning' option to position. value mappings (old -> new) are: [true -> 'absolute', false -> 'fixed', null -> 'auto']
  • renamed 'scrollingTop' to top and 'scrollingBottom' to bottom
  • removed cellTag and debounceResizeMs options
  • removed floatThead-floatContainer class from the $floatContainer because floatThead-container class is already there and it is configurable via floatContainerClass option.
  • added autoReflow option
  • https://github.com/mkoryak/floatThead/issues/235 - fix tabindex of the floated header (thanks robinpoort)
  • https://github.com/mkoryak/floatThead/issues/242 - support for multiple tables within a single scrolling div
  • https://github.com/mkoryak/floatThead/issues/246 - enableAria:true causes javascript exception when using Colgroup
  • fixed getRowGroups, method which was busted when the header was floated
  • make grunt work in node 0.12

1.2.13

  • https://github.com/mkoryak/floatThead/issues/220 - Header and Body alignment problem
  • package.json was incorrect
  • autoReflow option should work better if your browser supports MutationObserver
  • added native support for tables within bootstrap3 tabs or jqueryui tabs
  • if a tables is hidden, the plugin will not try do anything when you scroll
  • the cat is cute

1.2.12

Huge thanks to CoryDuncan, ithielnor, jurko-gospodnetic and mhwlng for your PRs

1.2.11

  • now supports perfect-scrollbar plugin
  • slightly better mobile safari support
  • fix bower.json

1.2.10

1.2.9

1.2.8

1.2.7

  • Changed license over to MIT

1.2.6

1.2.5

1.2.4

1.2.3

1.2.2

  • better support for tables with dynamically hidden columns
  • can now set a class on the floating header's container div

1.2.1

  • fixed issue with caption tag align:bottom
  • switched to uglifyjs to minify code

1.2.0

  • caption tag support
  • faster initialization when working with large tables (and small ones)

1.1.1

  • Fixed bugs introduced in 1.0.0 which caused issues in IE9

1.0.0

  • Updated code to be jquery 1.9+ compliant