material-react-table icon indicating copy to clipboard operation
material-react-table copied to clipboard

A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript

Material React Table


About

This project is still in alpha, but is expected to enter beta by August 2022, and a stable 1.0 release shortly thereafter.

  • A fully featured Material UI V5 implementation of Tanstack React Table V8
  • Inspired by material-table and the MUI X DataGrid
  • Written from the ground up in TypeScript
  • All internal Material UI components are easily customizable

Join the Discord server to join in on the development discussion or ask questions

View the Docs Website

See all Props and Options


Quick Examples

View additional storybook examples


Features (All Features work and are MVP, but are still being polished)

All features can easily be enabled/disabled

  • [x] < 37kb gzipped - Bundlephobia
  • [x] Advanced TypeScript Generics Support (TypeScript Optional)
  • [x] Aggregation and Grouping (Sum, Average, Count, etc.)
  • [x] Click To Copy Cell Values
  • [x] Column Action Dropdown Menu
  • [x] Column Hiding
  • [x] Column Ordering via Drag'n'Drop
  • [x] Column Pinning (Freeze Columns)
  • [x] Column Resizing
  • [x] Customize Icons
  • [x] Customize Styling of internal Mui Components
  • [x] Data Editing (3 different editing modes)
  • [x] Density Toggle
  • [x] Detail Panels (Expansion)
  • [x] Filtering (supports client-side and server-side)
  • [x] Full Screen Mode
  • [x] Global Filtering (Search across all columns, rank by best match)
  • [x] Header Groups & Footers
  • [x] Localization (i18n) support
  • [x] Manage your own state
  • [x] Pagination (supports client-side and server-side)
  • [x] Row Actions (Your Custom Action Buttons)
  • [x] Row Numbers
  • [x] Row Ordering via Drag'n'Drop
  • [x] Row Selection (Checkboxes)
  • [x] SSR compatible
  • [x] Sorting (supports client-side and server-side)
  • [x] Theming (Respects your Material UI Theme)
  • [x] Toolbars (Add your own action buttons)
  • [x] Tree Data / Expanding Sub-rows
  • [x] Virtualization (react-virtual)

Getting Started

Installation

View the full Installation Docs

  1. Install Peer Dependencies (Material UI V5)
npm install @mui/material @mui/icons-material @emotion/react @emotion/styled
  1. Install material-react-table
npm install material-react-table

@tanstack/react-table, @tanstack/react-virtual, and @tanstack/match-sorter-utils are internal dependencies, so you don't need to install them yourself.


Usage

Read the full usage docs here

import React, { useMemo, useState, useEffect } from 'react';
import MaterialReactTable from 'material-react-table';

export default function App() {
  const columns = useMemo(
    () => [
      {
        accessorKey: 'name', //simple recommended way to define a column
        header: 'Name',
        muiTableHeadCellProps: { sx: { color: 'green' } }, //custom props
      },
      {
        accessorFn: (row) => row.age, //alternate way
        id: 'age', //id required if you use accessorFn instead of accessorKey
        header: 'Age',
        Header: <i style={{ color: 'red' }}>Age</i>, //optional custom markup
      },
    ],
    [],
  );

  const data = useMemo(
    () => [
      {
        name: 'John',
        age: 30,
      },
      {
        name: 'Sara',
        age: 25,
      },
    ],
    [],
  );

  //optionally, you can manage any/all of the table state yourself
  const [rowSelection, setRowSelection] = useState({});

  useEffect(() => {
    //do something when the row selection changes
  }, [rowSelection]);

  return (
    <MaterialReactTable 
      columns={columns} 
      data={data} 
      enableColumnOrdering //enable some features
      enableRowSelection 
      enableStickyHeader
      onRowSelectionChange={setRowSelection} //hoist internal state to your own state (optional)
      state={{ rowSelection }} //manage your own state, pass it back to the table (optional)
   />
   );
}

Open in Code Sandbox


Contributors

PRs are Welcome, but please discuss in GitHub Discussions or the Discord Server first!