Convert Figma logo to code with AI

mkoryak logofloatThead

Fixed <thead>. Doesn't need any custom css/html. Does what position:sticky can't

1,219
196
1,219
3

Top Related Projects

Github fork of Christian Bach's tablesorter plugin + awesomeness ~

An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation, Vue.js)

DataTables but in TypeScript transpiled to Vanilla JS

JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡

Quick Overview

floatThead is a JavaScript library that allows table headers to float (stay visible) when scrolling through long tables. It works on any table and doesn't require any special CSS or markup. The library is designed to be fast, lightweight, and compatible with various browsers and devices.

Pros

  • Easy to implement with minimal setup required
  • Works with responsive tables and dynamically changing content
  • Supports both window and container scrolling
  • Lightweight and performant, with no dependencies

Cons

  • May not work perfectly with complex table structures or heavily styled tables
  • Limited customization options for the floating header appearance
  • Occasional issues with certain CSS frameworks or specific browser versions
  • Lack of recent updates (last commit was in 2019)

Code Examples

  1. Basic initialization:
$('table').floatThead();

This code initializes floatThead on all tables in the document with default options.

  1. Using container scrolling:
$('table').floatThead({
    scrollContainer: function($table){
        return $table.closest('.table-container');
    }
});

This example sets up floatThead to work with a scrollable container instead of the window.

  1. Responsive table with reflow:
var $table = $('table');
$table.floatThead({
    responsiveContainer: function($table){
        return $table.closest('.table-responsive');
    }
});

$(window).on('resize', function(){
    $table.floatThead('reflow');
});

This code sets up floatThead for a responsive table and triggers a reflow on window resize.

Getting Started

To use floatThead in your project, follow these steps:

  1. Include jQuery and floatThead in your HTML:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/floatthead/2.2.4/jquery.floatThead.min.js"></script>
  1. Initialize floatThead on your table:
$(document).ready(function(){
    $('table').floatThead();
});

That's it! Your table headers should now float when scrolling. You can customize the behavior by passing options to the floatThead() function as needed.

Competitor Comparisons

Github fork of Christian Bach's tablesorter plugin + awesomeness ~

Pros of tablesorter

  • More comprehensive table manipulation features (sorting, filtering, paging)
  • Extensive documentation and examples
  • Wider range of customization options and themes

Cons of tablesorter

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to more complex API

Code Comparison

floatThead:

$('table').floatThead();

tablesorter:

$('table').tablesorter({
  theme: 'blue',
  widgets: ['zebra', 'filter'],
  sortList: [[0,0], [1,0]]
});

Summary

floatThead is a lightweight library focused specifically on creating floating table headers, while tablesorter is a more comprehensive solution for table manipulation. floatThead is easier to implement for its specific use case, but tablesorter offers more features and customization options at the cost of increased complexity and file size.

Both libraries have active communities and regular updates. The choice between them depends on the specific requirements of your project. If you only need floating headers, floatThead may be the better option. For more advanced table functionality, tablesorter could be the preferred choice.

An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation, Vue.js)

Pros of bootstrap-table

  • More comprehensive table functionality, including sorting, filtering, and pagination
  • Extensive documentation and examples for various use cases
  • Active community with frequent updates and contributions

Cons of bootstrap-table

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to more complex API and configuration options
  • May require additional setup for basic floating header functionality

Code Comparison

bootstrap-table:

<table data-toggle="table" data-url="data.json">
  <thead>
    <tr>
      <th data-field="id">ID</th>
      <th data-field="name">Name</th>
      <th data-field="price">Price</th>
    </tr>
  </thead>
</table>

floatThead:

<table id="myTable">
  <thead>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Price</th>
    </tr>
  </thead>
  <!-- Table body -->
</table>
<script>
  $('#myTable').floatThead();
</script>

bootstrap-table offers a more feature-rich solution with built-in data loading and column configuration, while floatThead focuses specifically on creating floating headers with a simpler implementation. The choice between the two depends on the specific requirements of the project and the desired level of functionality.

DataTables but in TypeScript transpiled to Vanilla JS

Pros of simple-datatables

  • More comprehensive data table solution with built-in sorting, searching, and pagination
  • Easier to implement for full-featured data tables without additional plugins
  • Supports modern JavaScript and can be used as an ES6 module

Cons of simple-datatables

  • Larger file size and potentially higher overhead for simpler use cases
  • Less focused on specific table header functionality compared to floatThead
  • May require more configuration for custom styling and behavior

Code Comparison

simple-datatables:

import {DataTable} from 'simple-datatables'

const myTable = new DataTable("#myTable", {
    searchable: true,
    fixedHeight: true,
    perPage: 10
})

floatThead:

$('#myTable').floatThead({
    position: 'fixed',
    top: 50,
    scrollContainer: function($table){
        return $table.closest('.wrapper');
    }
});

Summary

simple-datatables offers a more comprehensive solution for creating interactive data tables with built-in features like sorting and pagination. It's better suited for projects requiring full-featured tables out of the box. floatThead, on the other hand, focuses specifically on floating table headers and may be more appropriate for simpler use cases or when integrating with existing table implementations. The choice between the two depends on the specific requirements of your project and the level of customization needed.

JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡

Pros of Handsontable

  • Full-featured data grid/spreadsheet component with extensive functionality
  • Supports various data types, formulas, and advanced cell editing
  • Offers both open-source and commercial versions with additional features

Cons of Handsontable

  • More complex to implement and configure due to its extensive feature set
  • Larger file size and potential performance impact for simpler use cases
  • Commercial license required for some advanced features

Code Comparison

Handsontable:

const container = document.getElementById('example');
const hot = new Handsontable(container, {
  data: data,
  rowHeaders: true,
  colHeaders: true,
  filters: true,
  dropdownMenu: true
});

FloatThead:

$('#myTable').floatThead({
  position: 'fixed',
  top: 50,
  scrollContainer: function($table){
    return $table.closest('.wrapper');
  }
});

Key Differences

  • Handsontable is a complete data grid solution, while FloatThead focuses solely on floating table headers
  • FloatThead is lighter and easier to implement for simple floating header requirements
  • Handsontable offers more advanced data manipulation and editing capabilities
  • FloatThead is generally more performant for large tables with simple floating header needs

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

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!

Around 153,000 hits on github code search

License

MIT

NPM DownloadsLast 30 Days