Top Related Projects
🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
Datatables for React using Material-UI
A responsive table library with built-in sorting, pagination, selection, expandable rows, and customizable styling.
Interactive Tables and Data Grids for JavaScript
The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.
Next Generation of react-bootstrap-table
Quick Overview
Reactable is a React table component library that provides a flexible and customizable way to create data tables in React applications. It offers features like sorting, filtering, and pagination, making it easier to handle large datasets and create interactive table experiences.
Pros
- Highly customizable with a wide range of configuration options
- Supports advanced features like sorting, filtering, and pagination out of the box
- Offers a clean and intuitive API for easy integration into React projects
- Provides good performance, even with large datasets
Cons
- Learning curve might be steep for beginners due to the extensive API
- Documentation could be more comprehensive and up-to-date
- Limited built-in styling options, requiring additional CSS for advanced designs
- Some users report occasional bugs and inconsistencies in certain edge cases
Code Examples
- Basic table setup:
import { Table, Tr, Td } from "reactable";
const MyTable = () => (
<Table className="table" data={[
{ name: "Griffin Smith", age: 18 },
{ name: "Lee Salminen", age: 23 },
{ name: "Ian Zhang", age: 28 }
]}>
<Tr>
<Td column="name">Name</Td>
<Td column="age">Age</Td>
</Tr>
</Table>
);
- Adding sorting functionality:
import { Table, Tr, Td } from "reactable";
const SortableTable = () => (
<Table className="table" data={data} sortable={['name', 'age']}>
<Tr>
<Td column="name">Name</Td>
<Td column="age">Age</Td>
</Tr>
</Table>
);
- Implementing filtering:
import { Table, Tr, Td, FilterableColumn } from "reactable";
const FilterableTable = () => (
<Table className="table" filterable={['name', 'age']} data={data}>
<Tr>
<Td column="name">Name</Td>
<Td column="age">Age</Td>
</Tr>
</Table>
);
Getting Started
To use Reactable in your project, follow these steps:
-
Install the package:
npm install reactable
-
Import the necessary components in your React file:
import { Table, Tr, Td } from "reactable";
-
Create a basic table component:
const MyTable = ({ data }) => ( <Table className="table" data={data}> <Tr> <Td column="name">Name</Td> <Td column="age">Age</Td> </Tr> </Table> );
-
Use the table component in your application, passing in your data as a prop.
Competitor Comparisons
🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
Pros of Table
- More active development and maintenance
- Supports multiple frameworks (React, Vue, Solid, Svelte)
- Extensive documentation and examples
Cons of Table
- Steeper learning curve due to more complex API
- Larger bundle size compared to Reactable
Code Comparison
Reactable:
<Table data={data}>
<Column header="Name" accessor="name" />
<Column header="Age" accessor="age" />
</Table>
Table:
const table = useReactTable({
data,
columns: [
{ header: 'Name', accessorKey: 'name' },
{ header: 'Age', accessorKey: 'age' },
],
})
Summary
Table offers more features and flexibility, supporting multiple frameworks and providing extensive documentation. However, it comes with a steeper learning curve and larger bundle size. Reactable, while simpler and lighter, has less active development and fewer features.
The code comparison shows that Reactable has a more declarative approach, while Table uses a more programmatic setup with hooks. This reflects the difference in complexity and flexibility between the two libraries.
Choose Table for complex, feature-rich tables across different frameworks, and Reactable for simpler React-specific tables with a smaller footprint.
Datatables for React using Material-UI
Pros of mui-datatables
- Built on Material-UI, providing a modern and consistent design
- Extensive customization options, including custom rendering for cells and toolbars
- Built-in responsive design for mobile devices
Cons of mui-datatables
- Larger bundle size due to Material-UI dependency
- Steeper learning curve for developers unfamiliar with Material-UI
- Less flexibility in table structure compared to Reactable
Code Comparison
mui-datatables:
import MUIDataTable from "mui-datatables";
const columns = ["Name", "Company", "City", "State"];
const data = [
["Joe James", "Test Corp", "Yonkers", "NY"],
["John Walsh", "Test Corp", "Hartford", "CT"],
];
const options = {
filterType: 'checkbox',
};
<MUIDataTable
title={"Employee List"}
data={data}
columns={columns}
options={options}
/>
Reactable:
import { Table, Tr, Td } from 'reactable';
<Table className="table" id="table">
<Tr>
<Td column="Name">Joe James</Td>
<Td column="Company">Test Corp</Td>
<Td column="City">Yonkers</Td>
<Td column="State">NY</Td>
</Tr>
<Tr>
<Td column="Name">John Walsh</Td>
<Td column="Company">Test Corp</Td>
<Td column="City">Hartford</Td>
<Td column="State">CT</Td>
</Tr>
</Table>
A responsive table library with built-in sorting, pagination, selection, expandable rows, and customizable styling.
Pros of react-data-table-component
- More active development and maintenance
- Extensive customization options and features
- Better TypeScript support
Cons of react-data-table-component
- Steeper learning curve due to more complex API
- Larger bundle size
Code Comparison
react-data-table-component:
import DataTable from 'react-data-table-component';
const columns = [
{ name: 'Title', selector: row => row.title },
{ name: 'Year', selector: row => row.year },
];
<DataTable columns={columns} data={data} />
Reactable:
import { Table, Tr, Td } from 'reactable';
<Table className="table" data={[
{ name: 'Griffin Smith', age: 18 },
{ name: 'Lee Salminen', age: 23 },
]}>
<Tr>
<Td column="name">Name</Td>
<Td column="age">Age</Td>
</Tr>
</Table>
react-data-table-component offers a more declarative approach with column definitions, while Reactable uses a more traditional table structure. react-data-table-component provides a more modern and flexible API, but Reactable may be simpler for basic use cases.
Interactive Tables and Data Grids for JavaScript
Pros of Tabulator
- More feature-rich with advanced functionality like filtering, sorting, and pagination
- Supports multiple data sources (JSON, AJAX, JavaScript arrays)
- Extensive documentation and active community support
Cons of Tabulator
- Larger file size and potentially higher performance overhead
- Steeper learning curve due to more complex API and configuration options
Code Comparison
Reactable:
<Reactable.Table className="table" data={data}>
<Reactable.Column key="name" label="Name" />
<Reactable.Column key="age" label="Age" />
</Reactable.Table>
Tabulator:
var table = new Tabulator("#example-table", {
data: data,
columns: [
{title: "Name", field: "name"},
{title: "Age", field: "age"}
]
});
Summary
Tabulator offers a more comprehensive set of features and flexibility, making it suitable for complex table requirements. However, this comes at the cost of a larger footprint and potentially more complex setup. Reactable, on the other hand, provides a simpler, React-specific solution that may be easier to integrate into existing React projects but with fewer built-in features.
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 pivoting, grouping, and filtering
- Better performance for large datasets, handling millions of rows efficiently
- Extensive documentation and community support
Cons of ag-grid
- Steeper learning curve due to its complexity and extensive API
- Larger bundle size, which may impact initial load times
- Commercial license required for some advanced features
Code Comparison
ag-grid:
import { AgGridReact } from 'ag-grid-react';
<AgGridReact
columnDefs={columnDefs}
rowData={rowData}
onGridReady={onGridReady}
pagination={true}
/>
Reactable:
import { Table } from "reactable";
<Table
data={data}
columns={columns}
sortable={true}
filterable={true}
/>
Key Differences
- ag-grid offers more built-in features and customization options
- Reactable has a simpler API and is easier to set up for basic use cases
- ag-grid provides better performance for large datasets
- Reactable is fully open-source, while ag-grid has a commercial version with additional features
Both libraries serve different needs: ag-grid is suitable for complex enterprise applications with large datasets, while Reactable is better for simpler projects requiring a straightforward table component.
Next Generation of react-bootstrap-table
Pros of react-bootstrap-table2
- More comprehensive documentation and examples
- Better integration with Bootstrap styling
- Active development and maintenance
Cons of react-bootstrap-table2
- Steeper learning curve due to more complex API
- Larger bundle size
Code Comparison
reactable:
<Reactable.Table className="table" data={data}>
<Reactable.Column key="name" label="Name" />
<Reactable.Column key="age" label="Age" />
</Reactable.Table>
react-bootstrap-table2:
<BootstrapTable keyField='id' data={data} columns={columns} />
The code comparison shows that react-bootstrap-table2 has a more concise syntax for basic table setup, while reactable offers a more declarative approach with explicit column definitions.
react-bootstrap-table2 provides a more feature-rich and actively maintained solution, with better Bootstrap integration. However, it may have a steeper learning curve and larger bundle size compared to reactable.
reactable offers a simpler API and smaller footprint, which might be preferable for projects with basic table requirements. However, it lacks some advanced features and has less active development.
Choose react-bootstrap-table2 for complex tables with Bootstrap styling, and reactable for simpler use cases or when a smaller bundle size is crucial.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Reactable
Fast, flexible, and simple data tables in React.
Reactable allows you to display tabular data client-side, and provides sorting, filtering, and pagination over that data. It uses the power of React.js to do all this very, very quickly, and provides an API that makes simple things easy, while trying to get out of your way as much as possible if you want to do something complicated or unconventional.
This project is currently alpha-stage, which means the API may or may not be unstable and there might be hidden bugs lurking around any corner. I'll try to tag any releases with breaking changes, however, and the more people who use this the faster we can get to 1.0!
Note: As of version 0.12.0 Reactable will only continue to support React 0.14 and higher.
Table of Contents
Installation
Using Bower
bower install [--save] reactable
Using NPM
npm install [--save] reactable
Or, you can just download the raw file here.
That file can be used either as an AMD module, as a CommonJS module in Node, or,
if neither are supported, will register the Reactable object as a property of
the window
object.
Reactable also exposes a set of CommonJS modules for piece-by-piece use with
Node, Webpack, Browserify, etc. These modules are located in the lib
folder
at the root of this repositiory.
Keep in mind that Reactable depends on the latest version of React (0.14), which can be downloaded here
Usage
The simplest example:
var Table = Reactable.Table;
ReactDOM.render(
<Table className="table" data={[
{ Name: 'Griffin Smith', Age: 18 },
{ Age: 23, Name: 'Lee Salminen' },
{ Age: 28, Position: 'Developer' },
]} />,
document.getElementById('table')
);
While pretty basic, this example demonstrates a couple things:
- Columns in the data array can be in any order, and you can omit any you like
- Regular React DOM attributes such as className will pass-through to the
rendered
<table>
- Data values can be any type with a
toString()
method
Further Customization
You can also manually build up your rows using Reactable.Tr
nested in a table,
also using the data
prop, but this time containing only one javascript object.
This approach can be freely combined with the data
property on the <Table>
,
and is useful if you want to specify per-row attributes such as classes, like so:
var Table = Reactable.Table,
Tr = Reactable.Tr;
ReactDOM.render(
<Table className="table" data={[
{ name: 'Row one', content: 'These are regular data rows' },
{ name: 'Row two', content: 'They work like above' },
]} >
<Tr className="special-row"
data={{ name: 'Other Row' , content: 'This is a different row' }} />
</Table>,
document.getElementById('table')
);
Even More Customization
If you want to customize the rendering of individual columns, you can go a level
deeper by embedding a Reactable.Td
inside your Reactable.Tr
. These have the
required column
property, and an optional value
property if you want to
customize the data that's used for sorting and filtering - if the latter isn't
specified, the data used will default to the Td
's children.
Example:
var Table = Reactable.Table,
Tr = Reactable.Tr,
Td = Reactable.Td;
ReactDOM.render(
<Table className="table" id="table">
<Tr>
<Td column="Name" data="Griffin Smith">
<b>Griffin Smith</b>
</Td>
<Td column="Age">18</Td>
</Tr>
<Tr>
<Td column="Name">Lee Salminen</Td>
<Td column="Age">23</Td>
</Tr>
<Tr>
<Td column="Position">Developer</Td>
<Td column="Age">28</Td>
</Tr>
</Table>,
document.getElementById('table')
);
Customizing Columns
To override inferring the column list from the attributes of the passed data
objects, you can either:
- Pass a
columns
array property to the<Table>
component, which can be either:- An array of strings, in which case only the given properties will be included as columns in the rendered table.
- An array of objects, each of which must have a
key
andlabel
property. Thekey
property is the attribute of the row object from which to retrieve value, and thelabel
is the text to render in the column header row.
- Define a
<Thead>
component as the first child of the<Table>
, with<Th>
components as children (note the exclusion of a<Tr>
here), each of which should have a "column" property. The children of these<Th>
components (either strings or React components themselves) will be used to render the table headers. For example:
var Table = Reactable.Table,
Thead = Reactable.Thead,
Th = Reactable.Th,
Tr = Reactable.Tr,
Td = Reactable.Td;
ReactDOM.render(
<Table className="table" id="table">
<Thead>
<Th column="name">
<strong className="name-header">First Name, Last Name</strong>
</Th>
<Th column="age">
<em className="age-header">Age, years</em>
</Th>
</Thead>
<Tr>
<Td column="name" data="Griffin Smith">
<b>Griffin Smith</b>
</Td>
<Td column="age">18</Td>
</Tr>
<Tr>
<Td column="name">Lee Salminen</Td>
<Td column="age">23</Td>
</Tr>
<Tr>
<Td column="position">Developer</Td>
<Td column="age">28</Td>
</Tr>
</Table>,
document.getElementById('table')
);
In this example, the position
column will not be rendered.
Additional node types
Reactable also supports specifying a <tfoot>
for your table, via the
Reactable.Tfoot
class. Per the HTML spec, there can only be one <Tfoot>
per
table and its only children should be React.DOM <tr>
elements (not
<Reactable.Tr>
elements).
Preventing escaping of HTML
If you don't want to go all the way down the JSX rabbit hole to render
individual cells as HTML, and you know your source data is safe, you can wrap
strings in Reactable.unsafe
to prevent their content from being escaped, like
so:
var Table = Reactable.Table,
unsafe = Reactable.unsafe;
ReactDOM.render(
<Table className="table" id="table" data={[
{
'Name': unsafe('<b>Griffin Smith</b>'),
'Github': unsafe('<a href="https://github.com/glittershark"><img src="https://d2k1ftgv7pobq7.cloudfront.net/images/services/8cab38550d1f23032facde191031d024/github.png"></a>')
},
{
'Name': unsafe('<b>Ian Zhang</b>'),
'Github': unsafe('<a href="https://github.com/lofiinterstate"><img src="https://d2k1ftgv7pobq7.cloudfront.net/images/services/8cab38550d1f23032facde191031d024/github.png"></a>')
},
]}/>,
document.getElementById('table')
);
You can also pass in unsafe
strings as column labels or in a <Reactable.Th>
Pagination
You can also use pagination, by just specifying an itemsPerPage
argument to
the <Table>
component. Include an optional pageButtonLimit
argument to
customize the number of page buttons in the pagination, which defaults to 10.
For example:
<Table className="table" data={[
{ Name: 'Griffin Smith', Age: '18' },
{ Age: '23', Name: 'Lee Salminen' },
{ Age: '28', Position: 'Developer' },
{ Name: 'Griffin Smith', Age: '18' },
{ Age: '30', Name: 'Test Person' },
{ Name: 'Another Test', Age: '26', Position: 'Developer' },
{ Name: 'Third Test', Age: '19', Position: 'Salesperson' },
{ Age: '23', Name: 'End of this Page', Position: 'CEO' },
]} itemsPerPage={4} pageButtonLimit={5} />
You can also change the default text on the buttons by including the
previousPageLabel
and nextPageLabel
props.
Sorting
To enable sorting on all columns, just specify sortable={true}
on the
<Table>
component. For further customization, ie disabling sort or using a
custom sort function on a per-column basis, you can pass an array to sortable
,
which contains either string column names or column objects.
We've pre-built some sort functions for you.
CaseInsensitive
will sort strings alphabetically regardless of capitalization (e.g. Joe Smith === joe smith)Date
will sort dates using JavaScript's native Date parser (e.g. 4/20/2014 12:05 PM)Currency
will sort USD format (e.g. $1,000.00)Numeric
will parse integer-like strings as integers (e.g. "1")NumericInteger
will parse integer strings (useNumeric
if you might have floats)
To specify a custom sort function, use the following structure for the column object:
{column: 'Column Name', sortFunction: function(a, b){
return a > b ? 1 : -1;
}}
You can also specify a default sort by passing in either a column name by
itself, or an object with a column and a direction
paramenter of either asc
or desc
. If no direction is specified, the default sort will be ascending.
Example:
{column: 'Column Name', direction: 'asc' }
Combined example:
<Table className="table" id="table" data={[
{ Name: 'Lee Salminen', Age: '23', Position: 'Programmer'},
{ Name: 'Griffin Smith', Age: '18', Position: 'Engineer'},
{ Name: 'Ian Zhang', Age: '28', Position: 'Developer'}
]}
sortable={[
{
column: 'Name',
sortFunction: function(a, b){
// Sort by last name
var nameA = a.split(' ');
var nameB = b.split(' ');
return nameA[1].localeCompare(nameB[1]);
}
},
'Age',
'Position'
]}
defaultSort={{column: 'Age', direction: 'desc'}}/>
In case you are constructing your table without the data attribute, and the cells contain some additional HTML elements, you can use the value property on the Td element to define the value to sort for.
In the following example we define two TDs, where the first contains some additional markup. We tell the Td to take "Griffin Smith" as value for data handling (filter or sort).
var Table = Reactable.Table,
Tr = Reactable.Tr,
Td = Reactable.Td;
ReactDOM.render(
<Table className="table" id="table" sortable={true}>
<Tr>
<Td column="Name" value="Griffin Smith">
<div>
<span>Some Text or Icon</span>
<b>Griffin Smith</b>
</div>
</Td>
<Td column="Age">18</Td>
</Tr>
</Table>,
document.getElementById('table')
);
There is also an boolean defaultSortDescending
option to default the sorting
of a column to descending when clicked:
<Table className="table" id="table" data={[
{ Name: 'Lee Salminen', Age: '23', Position: 'Programmer'},
{ Name: 'Griffin Smith', Age: '18', Position: 'Engineer'},
{ Name: 'Ian Zhang', Age: '28', Position: 'Developer'}
]}
sortable={[
'Age',
'Position'
]}
defaultSort={{column: 'Age', direction: 'desc'}}
defaultSortDescending
Filtering
You can do simple case-insensitive filtering by specifying a filterable property on the table. This property should contain a list of columns which the filter is performed on. If the filterable property is provided, then an input box with class reactable-filter-input will be prepended to the thead of the table.
Example:
<Table className="table" id="table" data={[
{'State': 'New York', 'Description': 'this is some text', 'Tag': 'new'},
{'State': 'New Mexico', 'Description': 'lorem ipsum', 'Tag': 'old'},
{'State': 'Colorado',
'Description': 'new description that shouldn\'t match filter',
'Tag': 'old'},
{'State': 'Alaska', 'Description': 'bacon', 'Tag': 'renewed'},
]} filterable={['State', 'Tag']} />
There is also a filterBy()
function on the component itself which takes a
single string and applies that as the filtered value. It can be used like so:
var table = ReactDOM.render(
<Table className="table" id="table" data={[
{'State': 'New York', 'Description': 'this is some text', 'Tag': 'new'},
{'State': 'New Mexico', 'Description': 'lorem ipsum', 'Tag': 'old'},
{'State': 'Colorado',
'Description': 'new description that shouldn\'t match filter',
'Tag': 'old'},
{'State': 'Alaska', 'Description': 'bacon', 'Tag': 'renewed'},
]} filterable={['State', 'Tag']} />,
document.getElementById('table')
);
table.filterBy('new');
You can also pass in a filterBy
prop to control the filtering outside of the
Table
component:
var table = ReactDOM.render(
<Table className="table" id="table" data={[
{'State': 'New York', 'Description': 'this is some text', 'Tag': 'new'},
{'State': 'New Mexico', 'Description': 'lorem ipsum', 'Tag': 'old'},
{'State': 'Colorado',
'Description': 'new description that shouldn\'t match filter',
'Tag': 'old'},
{'State': 'Alaska', 'Description': 'bacon', 'Tag': 'renewed'},
]} filterable={['State', 'Tag']}
filterBy="new" />,
document.getElementById('table')
);
If you are using your own input field to control the filterBy
prop, you can
hide the build-in filter input field with the hideFilterInput
prop:
var table = ReactDOM.render(
<Table className="table" id="table" data={[
{'State': 'New York', 'Description': 'this is some text', 'Tag': 'new'},
{'State': 'New Mexico', 'Description': 'lorem ipsum', 'Tag': 'old'},
{'State': 'Colorado',
'Description': 'new description that shouldn\'t match filter',
'Tag': 'old'},
{'State': 'Alaska', 'Description': 'bacon', 'Tag': 'renewed'},
]} filterable={['State', 'Tag']}
filterBy="new"
hideFilterInput />,
document.getElementById('table')
);
These can be useful if you want to roll your own filtering input field outside of Reactable.
You can also provide your own custom filtering functions:
<Table className="table" id="table" data={[
{'State': 'New York', 'Description': 'this is some text', 'Tag': 'new'},
{'State': 'New Mexico', 'Description': 'lorem ipsum', 'Tag': 'old'},
{'State': 'Colorado',
'Description': 'new description that shouldn\'t match filter',
'Tag': 'old'},
{'State': 'Alaska', 'Description': 'bacon', 'Tag': 'renewed'},
]}
filterable={[
{
column: 'State',
filterFunction: function(contents, filter) {
// case-sensitive filtering
return (contents.indexOf(filter) > -1);
}
},
'Tag'
]} />
Your filter function must return a boolean. Refraining from specifying a custom filter function will default to case-insensitive filtering.
Empty Data Sets
If the table is initialized without any <Tr>
s or with an empty array for
data
, you can display text in the body of the table by passing a string
for the optional noDataText
prop:
var table = ReactDOM.render(
<Table
className="table"
id="table" data={[]}
noDataText="No matching records found." />,
document.getElementById('table')
);
Events
You can pass functions to the following props of <Reactable.Table>
to provide
event handlers.
onSort
Called when the sorting in the table changes.
This handler will be passed an object that contains the column name that is being sorted by, and the direction it is being sorted:
{
column: 'Name',
direction: -1
}
onFilter
Called every time the filtering changes.
This handler will be passed a string containing the text that's being used for filtering.
onPageChange
Called every time the page changes.
This handler will be passed a number representing the current page, zero based.
Top Related Projects
🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
Datatables for React using Material-UI
A responsive table library with built-in sorting, pagination, selection, expandable rows, and customizable styling.
Interactive Tables and Data Grids for JavaScript
The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.
Next Generation of react-bootstrap-table
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot