Skip to content

Keep tables header floating while scrolling #html #jquery #jqueryui #javascript

License

Notifications You must be signed in to change notification settings

oriadam/floating_thead

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

floating_thead

jQuery plugin to keep table header row on screen while scrolling down the table. A position:sticky alternative/fallback. jQueryUI is optional, will be used to get the scrollParent.

Usage:

jQuery('table').floating_thead();

Advanced:

jQuery('table').floating_thead({
    scrollParent: jQuery('body'), // this line is mandatory when jQueryUI is missing
    on_scroll: function ($table, $thead, $scrollParent)
    {
        $thead.css('margin-top', $scrollParent[0].scrollTop ? 60 : 0);
    }
});

// update table sizes
jQuery('table').trigger('floating_thead_refresh');

Notes:

  • Nothing is cloned, only css is changed
  • When thead is fixed the table will have class floating_thead_on
  • Window resize will trigger recalculation of column widths
  • Scrolling element is detected using jQueryUI .scrollParent(). If jQueryUI is absent you must pass scrollParent in options

About

Keep tables header floating while scrolling #html #jquery #jqueryui #javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published