Skip to content

OliverJAsh/sticky-table-header

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sticky Table Header

Progressively enhance a table so the header sticks as you scroll vertically.

Demo

This works by cloning the thead and positioning it according to the user's scroll position inside a wrapper element.

This library works under some assumptions:

  • cells with borders will have box-sizing: border-box
  • cellspacing will be set to 0
  • the input table element will have a thead and tbody

The table should be transformed so that:

  • thead should stick when scrolling vertically
  • thead should not stick when scrolling horizontally
  • thead cells should grow/shrink to column contents from tbody

Installation

# Distributed as a UMD module with the global name `initStickyTableHeader`
npm install sticky-table-header

Example

See code example.

Development

npm install
npm run compile
http-server -c-1 ./target
# Once the server is running, see /example.html

API

(tableEl: HTMLTableElement, height?: number) => { destroy: () => void, applyColumnWidths: () => void }

About

Progressively enhance a table so the header sticks as you scroll vertically.

Resources

Stars

Watchers

Forks

Packages

No packages published