Convert Figma logo to code with AI

filamentgroup logotablesaw

A group of plugins for responsive tables.

5,480
434
5,480
0

Top Related Projects

Tables plug-in for jQuery

3,611

Plotting library for IPython/Jupyter notebooks

12,496

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

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

A lightning fast JavaScript grid/spreadsheet

The Missing Javascript Datatable for the Web

Quick Overview

Tablesaw is a JavaScript library that enhances HTML tables, making them responsive and interactive. It provides features like sorting, filtering, and pagination, while also ensuring tables are usable on mobile devices through various modes of responsiveness.

Pros

  • Lightweight and easy to implement
  • Offers multiple responsive modes for different use cases
  • Provides advanced features like sorting, filtering, and pagination
  • Customizable and extensible

Cons

  • Limited styling options out of the box
  • May require additional setup for complex table structures
  • Documentation could be more comprehensive
  • Some features may not work well with very large datasets

Code Examples

Initializing Tablesaw:

$(document).ready(function() {
  $('table').tablesaw();
});

Adding sorting functionality:

<table class="tablesaw tablesaw-sortable" data-tablesaw-mode="sortable">
  <thead>
    <tr>
      <th data-tablesaw-sortable-col>Name</th>
      <th data-tablesaw-sortable-col data-tablesaw-sortable-default-col>Age</th>
    </tr>
  </thead>
  <tbody>
    <!-- Table content -->
  </tbody>
</table>

Implementing stack mode for responsive tables:

<table class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <!-- Table content -->
  </tbody>
</table>

Getting Started

  1. Include the Tablesaw CSS and JavaScript files in your HTML:
<link rel="stylesheet" href="path/to/tablesaw.css">
<script src="path/to/tablesaw.js"></script>
  1. Add the appropriate classes and data attributes to your HTML table:
<table class="tablesaw" data-tablesaw-mode="stack">
  <!-- Table content -->
</table>
  1. Initialize Tablesaw in your JavaScript:
$(document).ready(function() {
  $('table').tablesaw();
});
  1. Customize as needed by adding additional classes and data attributes for sorting, filtering, or other features.

Competitor Comparisons

Tables plug-in for jQuery

Pros of DataTables

  • More feature-rich with advanced sorting, filtering, and pagination options
  • Extensive documentation and large community support
  • Highly customizable with numerous plugins and extensions

Cons of DataTables

  • Heavier footprint, which may impact page load times
  • Steeper learning curve due to its extensive API and options
  • Requires jQuery, which may not be ideal for all projects

Code Comparison

DataTables:

$(document).ready(function() {
    $('#myTable').DataTable({
        paging: true,
        searching: true,
        ordering: true
    });
});

Tablesaw:

<table class="tablesaw" data-tablesaw-mode="stack">
    <thead>
        <tr>
            <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="persist">Header 1</th>
            <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="1">Header 2</th>
        </tr>
    </thead>
    <tbody>
        <!-- Table content -->
    </tbody>
</table>

Both libraries offer table enhancement features, but they differ in approach and complexity. DataTables provides a more comprehensive solution with extensive JavaScript-based functionality, while Tablesaw focuses on a lightweight, mobile-first approach with minimal JavaScript requirements.

3,611

Plotting library for IPython/Jupyter notebooks

Pros of bqplot

  • Interactive and customizable data visualization library for Jupyter notebooks
  • Supports a wide range of chart types and complex visualizations
  • Seamless integration with the Jupyter ecosystem and ipywidgets

Cons of bqplot

  • Steeper learning curve due to its extensive features and flexibility
  • Primarily designed for use within Jupyter notebooks, limiting standalone usage
  • May have performance issues with large datasets compared to more lightweight libraries

Code Comparison

bqplot:

from bqplot import pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)
fig = plt.figure()
plt.plot(x, y)
plt.show()

Tablesaw:

<table class="tablesaw" data-tablesaw-mode="swipe">
  <thead>
    <tr>
      <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="persist">Header 1</th>
      <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="1">Header 2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Row 1, Cell 1</td>
      <td>Row 1, Cell 2</td>
    </tr>
  </tbody>
</table>

Note: The code comparison highlights the different focus of these libraries. bqplot is a Python library for creating interactive charts, while Tablesaw is a JavaScript library for responsive tables.

12,496

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

Pros of ag-grid

  • More feature-rich with advanced functionality like filtering, sorting, and grouping
  • Better performance for large datasets
  • Extensive documentation and community support

Cons of ag-grid

  • Steeper learning curve due to complexity
  • Larger file size and potential performance impact for smaller applications
  • Commercial license required for some advanced features

Code Comparison

ag-grid:

const gridOptions = {
  columnDefs: [
    { field: 'name' },
    { field: 'age' },
    { field: 'country' }
  ],
  rowData: [
    { name: 'John', age: 35, country: 'USA' }
  ]
};

Tablesaw:

<table class="tablesaw" data-tablesaw-mode="stack">
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
      <th>Country</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>John</td>
      <td>35</td>
      <td>USA</td>
    </tr>
  </tbody>
</table>

ag-grid offers a more programmatic approach with JavaScript configuration, while Tablesaw uses HTML markup with data attributes for functionality. ag-grid provides more control and customization options, but Tablesaw is simpler to implement for basic responsive tables.

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

Pros of Handsontable

  • More feature-rich with advanced functionalities like data validation, sorting, and filtering
  • Supports various data types and formats, including spreadsheet-like formulas
  • Extensive API and plugin system for customization

Cons of Handsontable

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to its complexity
  • Commercial license required for some features

Code Comparison

Handsontable:

const hot = new Handsontable(container, {
  data: dataset,
  rowHeaders: true,
  colHeaders: true,
  filters: true,
  dropdownMenu: true
});

Tablesaw:

<table class="tablesaw" data-tablesaw-mode="swipe">
  <thead>
    <tr>
      <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="persist">Header 1</th>
      <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="1">Header 2</th>
    </tr>
  </thead>
  <tbody>
    <!-- Table rows -->
  </tbody>
</table>

Summary

Handsontable offers a more comprehensive solution for complex data manipulation and spreadsheet-like functionality, while Tablesaw focuses on providing a lightweight, responsive table solution with basic sorting and filtering capabilities. Handsontable is better suited for advanced data management needs, whereas Tablesaw is ideal for simpler, mobile-friendly table implementations.

A lightning fast JavaScript grid/spreadsheet

Pros of SlickGrid

  • Highly performant with large datasets (100,000+ rows)
  • Advanced features like frozen columns and rows
  • Extensive API for customization and integration

Cons of SlickGrid

  • Steeper learning curve due to complexity
  • Less responsive design out of the box
  • Requires more setup for basic functionality

Code Comparison

SlickGrid:

var grid = new Slick.Grid("#myGrid", data, columns, options);
grid.setSelectionModel(new Slick.CellSelectionModel());
grid.registerPlugin(new Slick.AutoTooltips());

Tablesaw:

<table class="tablesaw" data-tablesaw-mode="swipe">
  <thead>
    <tr>
      <th scope="col" data-tablesaw-priority="persist">Header 1</th>
      <th scope="col">Header 2</th>
    </tr>
  </thead>
  <tbody>
    <!-- Table content -->
  </tbody>
</table>

SlickGrid offers more programmatic control and is better suited for complex, data-heavy applications. Tablesaw, on the other hand, provides a simpler, more declarative approach that's easier to implement for basic responsive tables. SlickGrid excels in performance with large datasets, while Tablesaw focuses on responsive design and ease of use for smaller to medium-sized tables.

The Missing Javascript Datatable for the Web

Pros of Datatable

  • More feature-rich with advanced functionality like cell editing, column resizing, and custom cell renderers
  • Better performance for large datasets due to virtual DOM rendering
  • Modern and actively maintained codebase with regular updates

Cons of Datatable

  • Steeper learning curve due to more complex API and configuration options
  • Larger file size and potentially higher memory usage
  • Requires JavaScript to function, less accessible for non-JS environments

Code Comparison

Tablesaw basic initialization:

$(document).ready(function() {
  $('table').tablesaw();
});

Datatable basic initialization:

const datatable = new DataTable('#myTable', {
  columns: ['Name', 'Age', 'City'],
  data: [
    ['John', 30, 'New York'],
    ['Jane', 25, 'London']
  ]
});

Summary

Tablesaw is simpler and more lightweight, focusing on responsive tables with basic sorting and filtering. It's easier to set up but has fewer advanced features. Datatable offers a more comprehensive solution with advanced functionality, better performance for large datasets, and a modern codebase. However, it comes with a steeper learning curve and higher resource requirements. Choose Tablesaw for simple, responsive tables with minimal setup, or Datatable for feature-rich, high-performance tables in complex applications.

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

:warning: This project is archived and the repository is no longer maintained.

Tablesaw

npm version Build Status Dependency Status

Filament Group

A set of plugins for responsive tables.

Roadmap and Enhancement Queue

This repository is now using lodash style issue management for enhancements. This means enhancement issues will be closed instead of leaving them open.

  • Look through the enhancement backlog and vote for your favorite features by adding a 👍 to the top comment.

Stack Mode

The Stack Table stacks the table headers to a two column layout with headers on the left when the viewport width is less than 40em (640px).

<table class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">

If you only want to use the Stack Table and don’t want all the extra features below (save yourself some bytes), Tablesaw provides a Stack-Only version.

OptionDescription
Opt out of inline labelsTo opt-out of inline label creation (the table header cell text that shows at small breakpoints) on a per-table basis, use <table data-tablesaw-no-labels>; on a per-row basis, use <tr data-tablesaw-no-labels>; on a per-cell basis, use <td data-tablesaw-no-labels> (added in v3.1.0)
Hide headers for empty body cellsWhen the table cell is empty, use <table data-tablesaw-hide-empty> to hide the header when stacked.

Column Toggle Mode

The Column Toggle Table allows the user to select which columns they want to be visible.

<table data-tablesaw-mode="columntoggle">
OptionDescription
Add a Mini-MapThe little dots that appear next to the column toggle popup. Use the data-tablesaw-minimap attribute: <table data-tablesaw-mode="columntoggle" data-tablesaw-minimap>

The user always has the option to select all columns. If the table gets too wide for the viewport, it can overflow and cause a page-level scrollbar. To combat this issue, we recommend wrapping your table in a <div class="tablesaw-overflow"> element to restrict scrolling to the table-only. The toggle demo has one such example.

Advanced Option: Prioritize Columns

Table headers must have a data-tablesaw-priority attribute to be eligible to toggle. data-tablesaw-priority is a numeric value from 1 to 6, which determine default breakpoints at which a column will show. The breakpoint defaults are:

<th data-tablesaw-priority="persist"><!-- Not eligible for toggle, always shows --></th>
<th data-tablesaw-priority="0"><!-- Hidden at all breakpoints by default, must be toggled back on manually --></th>
<th data-tablesaw-priority="1"><!-- Shows at (min-width: 20em) (320px) --></th>
<th data-tablesaw-priority="2"><!-- Shows at (min-width: 30em) (480px) --></th>
<th data-tablesaw-priority="3"><!-- Shows at (min-width: 40em) (640px) --></th>
<th data-tablesaw-priority="4"><!-- Shows at (min-width: 50em) (800px) --></th>
<th data-tablesaw-priority="5"><!-- Shows at (min-width: 60em) (960px) --></th>
<th data-tablesaw-priority="6"><!-- Shows at (min-width: 70em) (1120px) --></th>

Keep in mind that the priorities are not exclusive—multiple columns can reuse the same priority value.

Swipe Mode

Allows the user to use the swipe gesture (or use the left and right buttons) to navigate the columns.

<table data-tablesaw-mode="swipe">
OptionsDescription
Persist a ColumnColumns also respect the data-tablesaw-priority="persist" attribute: <th data-tablesaw-priority="persist"><!-- Always shows --></th>
Add a Mini-MapThe little dots that appear next to the column navigation buttons. Use the data-tablesaw-minimap attribute: <table data-tablesaw-mode="swipe" data-tablesaw-minimap>
All columns visible classTablesaw also exposes a tablesaw-all-cols-visible class that is toggled on when all of the table columns are visible (and off when not). You can use this in CSS to hide the minimap or navigation buttons if needed.
Disable swipe touch eventsUse the <table data-tablesaw-no-touch> attribute to opt-out of swiping left or right to navigate columns. Users will need to use the provided buttons instead.
Advanced Option: Configure Swipe Thresholds

Add a TablesawConfig object to your page in a <script> element. It doesn’t matter if it’s declared before or after the Tablesaw JavaScript.

<script>
TablesawConfig = {
  swipeHorizontalThreshold: 15,
  swipeVerticalThreshold: 20
};
</script>

Mini Map

Use data-tablesaw-minimap to add a series of small dots to show which columns are currently visible and which are hidden. Only available on swipe and columntoggle tables. Examples available above.

Mode Switcher

<table data-tablesaw-mode-switch>

<!-- With a different default mode -->
<table data-tablesaw-mode-switch data-tablesaw-mode="swipe">

<!-- Exclude a mode from the switcher -->
<table data-tablesaw-mode-switch data-tablesaw-mode-exclude="columntoggle">

Sortable

The “sortable” option allows the user to sort the table data by clicking on the table headers. Since all the columns may not be visible on smaller breakpoints (or not there at all if using the “stack” table mode), relying solely on the column headers to choose the table sort isn’t practical. To address this, there is an optional data-tablesaw-sortable-switch attribute on the table that adds a select menu auto-populated with the names of each column in the table with options for choosing ascending or descending sort direction. Data options on table headers can be used to control which columns are sortable (data-tablesaw-sortable-col) and the default sort order (data-tablesaw-sortable-default-col).

<table data-tablesaw-sortable>
    <thead>
        <tr>
            <!-- Default column -->
            <th data-tablesaw-sortable-col data-tablesaw-sortable-default-col>Rank</th>
            <th data-tablesaw-sortable-col>Movie Title</th>
            <th data-tablesaw-sortable-col data-tablesaw-sortable-numeric>Year</th>
            <th data-tablesaw-sortable-col data-tablesaw-sortable-numeric><abbr title="Rotten Tomato Rating">Rating</abbr></th>
            <!-- Unsortable column -->
            <th>Reviews</th>
        </tr>
    </thead>
    ...

Use data-tablesaw-sortable-switch to add a select form element to manually choose the sort order.

<table data-tablesaw-sortable data-tablesaw-sortable-switch>

Advanced Option: Custom Sort Functions

Tablesaw provides two methods of sorting built-in: string and numeric. To use numeric sort, use the data-tablesaw-sortable-numeric class as shown in the above sorting markup example. Otherwise, tablesaw uses a case insensitive string sort.

All other types of sorting must use a Custom Sort function on the individual columns (working example). In the contrived example below, we want to sort full dates (e.g. 12/02/2014) just on the year.

// Add a data function to the table header cell
$( "th#custom-sort" ).data( "tablesaw-sort", function( ascending ) {
    // return a function
    return function( a, b ) {
        // Ignore rows with data-tablesaw-ignorerow (leave them where they were)
        if( a.ignored || b.ignored ) {
            return 0;
        }

        // use a.cell and b.cell for cell values
        var dateA = a.cell.split( "/" ),
            dateB = b.cell.split( "/" ),
            yearA = parseInt( dateA[ 2 ], 10 ),
            yearB = parseInt( dateB[ 2 ], 10 );

        if( ascending ) {
            return yearA >= yearB ? 1 : -1;
        } else { // descending
            return yearA < yearB ? 1 : -1;
        }
    };
});

Kitchen Table Sink

All of the above options combined into a single table.

Check All

Added in 3.0.1. Add the data-tablesaw-checkall to a checkbox in a thead cell to enable that checkbox to toggle the other checkboxes in the same column.

Internationalization i18n

Added in 3.0.2. Use the TablesawConfig global on your page to override internationalization strings. It doesn’t matter if it’s declared before or after the Tablesaw JavaScript library.

<script>
TablesawConfig = {
  i18n: {
    modeStack: 'Stack',
    modeSwipe: 'Swipe',
    modeToggle: 'Toggle',
    modeSwitchColumnsAbbreviated: 'Cols',
    modeSwitchColumns: 'Columns',
    columnToggleButton: 'Columns',
    columnToggleError: 'No eligible columns.',
    sort: 'Sort',
    swipePreviousColumn: 'Previous column',
    swipeNextColumn: 'Next column'
  }
};
</script>

Getting Started

Available through npm:

npm install tablesaw

The Full Tablesaw

Tablesaw (no dependencies)
<link rel="stylesheet" href="tablesaw.css">
<script src="tablesaw.js"></script>
<script src="tablesaw-init.js"></script>
or Tablesaw (jQuery Plugin)
<link rel="stylesheet" href="tablesaw.css">
<!-- load your own jQuery -->
<script src="jquery.js"></script>
<script src="tablesaw.jquery.js"></script>
<script src="tablesaw-init.js"></script>

Don’t forget to add your table markup! For a stack table, this is how it’d look:

<table class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">

The demos above include full markup examples for all of the Tablesaw types.

Manual initialization of Tablesaw Components

If you want to initialize your Tablesaw tables manually, don’t include <script src="tablesaw-init.js"> in your markup. Instead, you can use Tablesaw.init(). This will scan the tree for any Tablesaw tables and initialize them for you.

Tables must be visible for proper initialization.

Tablesaw.init();
Tablesaw.init( myElement ); // OR pass an element to only init within a context

Dynamically Loading Tablesaw

For user interfaces that are dynamically built, Tablesaw can be loaded on an as-needed basis.
Here's how you might do this with jQuery:

$('head').append('<script src="tablesaw.js"></script>');

Following that, tables may be initialized manually as they are created.

Using Stack-Only Tablesaw

As shown above, we provide a Stack-mode-only package of Tablesaw. It’s a barebones version that doesn’t include any of the other features above.

Stack-only Tablesaw (no dependencies)
<link rel="stylesheet" href="tablesaw.css">
<script src="stackonly/tablesaw.stackonly.js"></script>
<script src="tablesaw-init.js"></script>
or just Stack-only Tablesaw (jQuery Plugin)
<link rel="stylesheet" href="tablesaw.css">
<!-- load your own jQuery -->
<script src="jquery.js"></script>
<script src="stackonly/tablesaw.stackonly.jquery.js"></script>
<script src="tablesaw-init.js"></script>

And then:

<table class="tablesaw tablesaw-stack" data-tablesaw-mode="stack">

Using Stack-Only Tablesaw SCSS Mixin

To easily customize the breakpoint at which the stack table switches, use the SCSS mixin. First, include the tablesaw.stackonly.scss file instead of tablesaw.stackonly.css in your SASS. Then, use a parent selector on your table.

<div class="my-parent-selector">
    <table class="tablesaw" data-tablesaw-mode="stack">

Include the mixin like so:

.my-parent-selector {
  @include tablesaw-stack( 50em );
}

The argument to tablesaw-stack is the breakpoint at which the table will switch from columns to stacked.

Default Styles

Starting with Tablesaw 3.0, the “Bare”, or stripped down style version of Tablesaw has been made the default.

Some of the more intrusive default styles have instead moved to opt-in classes you can add to the <table> element:

  • tablesaw-row-border: Adds a bottom border to each table row.
  • tablesaw-row-zebra: Adds a light background color to every other table row.
  • tablesaw-swipe-shadow: Adds the light shadow to the right of persistant columns to make them stand out a little more.

Limitations

  • Simple colspan and rowspan are supported, in part thanks to a lovely PR from @jgibson.
StackColumn ToggleSwipeSortable
rowspanNot yet supported (#247)SupportedSupportedNot yet supported (#268)
colspanSupportedSupportedSupportedSupported

Tests

Browser Support

All major browsers (evergreens are not listed, but supported). Notably this project cuts the mustard for A-grade support with:

  • Internet Explorer 9+
  • Android Browser 2.3+
  • Blackberry OS 6+

Other legacy browsers and Opera Mini receive unenhanced table markup.

Bundler Compatibility

Building the Project Locally

Run npm install to install dependencies and then grunt to build the project files into the dist folder.

Release Names

Previous versions didn’t have names.

NPM DownloadsLast 30 Days