Skip to content

Repository files navigation

MUI Table

A reusable table component for React applications built with Material-UI (MUI) and Material React Table.

Features

  • 🎨 Material-UI Integration: Built with MUI components for consistent design
  • 📊 Material React Table: Powered by Material React Table for advanced table functionality
  • 🔧 TypeScript: Full TypeScript support with proper type definitions
  • 📱 Responsive: Mobile-friendly and responsive design
  • 🎯 Customizable: Highly customizable with extensive props and options
  • Performance: Optimized for performance with virtual scrolling support
  • 🔍 Search & Filter: Built-in search and filtering capabilities
  • 📄 Pagination: Server-side and client-side pagination support
  • 🎨 Theming: Supports MUI theming system
  • 🎯 Row Selection: Single and multi-row selection support
  • 📌 Column Pinning: Pin columns to left or right
  • 🔄 Column Ordering: Drag and drop column reordering
  • 📊 Detail Panels: Expandable row details
  • 🎨 Custom Styling: Extensive styling customization options

Installation

npm install mui-table-react

or

yarn add mui-table-react

Peer Dependencies

This package requires the following peer dependencies:

{
"@mui/material": "^5.0.0",
"@types/react": "^18.0.0 || ^19.0.0",
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0"
}

Note:@types/react is optional and only needed for TypeScript projects.

Dependencies

The package includes these dependencies:

{
"@tanstack/react-table": "^8.20.5",
"dayjs": "^1.11.10",
"lodash": "^4.17.21",
"material-react-table": "^3.0.1",
"@mui/icons-material": "^5.0.0",
"@mui/x-date-pickers": "^7.18.0"
}

Usage

importReactfrom'react';import{MuiTable}from'mui-table-react';constMyComponent=()=>{constdata=[{id: 1,name: 'John Doe',email: 'john@example.com'},{id: 2,name: 'Jane Smith',email: 'jane@example.com'},];constcolumns=[{accessorKey: 'name',header: 'Name'},{accessorKey: 'email',header: 'Email'},];return(<MuiTabledata={data}columns={columns}enablePagination={true}enableSorting={true}enableGlobalFilter={true}/>);};

Props

Core Props

PropTypeDefaultDescription
dataArray<object>[]The data to display in the table
columnsArray<ColumnDef>[]Column definitions for the table
isLoadingbooleanfalseShows loading state
tableRefRefObjectnullReference to the table container

Feature Toggle Props

PropTypeDefaultDescription
enablePaginationbooleantrueEnable pagination
enableSortingbooleanfalseEnable column sorting
enableGlobalFilterbooleantrueEnable global search
enableRowSelectionbooleanfalseEnable row selection
enableColumnFiltersbooleantrueEnable column filters
enableColumnPinningbooleanfalseEnable column pinning
enableColumnOrderingbooleanfalseEnable column reordering
enableColumnDraggingbooleanfalseEnable column dragging
enableStickyHeaderbooleantrueEnable sticky header
enableTopToolbarbooleantrueEnable top toolbar
enableBottomToolbarbooleantrueEnable bottom toolbar
enableToolbarInternalActionsbooleantrueEnable internal toolbar actions
enableMultiRowSelectionbooleantrueEnable multi-row selection
enableSelectAllbooleantrueEnable select all functionality
enableExpandAllbooleantrueEnable expand all functionality
enableFacetedValuesbooleantrueEnable faceted values
enableHidingbooleanfalseEnable column hiding
enableDensityTogglebooleanfalseEnable density toggle
enableFullScreenTogglebooleanfalseEnable full screen toggle
enableCellActionsbooleanfalseEnable cell actions
enableColumnActionsbooleanfalseEnable column actions

Display Props

PropTypeDefaultDescription
showColumnFiltersbooleanfalseShow column filters by default
showGlobalFilterbooleantrueShow global filter by default
visibleInShowHideMenubooleanfalseShow in column visibility menu
manualPaginationbooleantrueEnable server-side pagination
manualExpandingbooleanfalseEnable manual expanding

Configuration Props

PropTypeDefaultDescription
rowCountnumber-Total row count for server-side pagination
leftFixedColumnIdsstring[][]IDs of columns to pin to the left
rightFixedColumnIdsstring[][]IDs of columns to pin to the right
columnOrderstring[][]Custom column order
paginationDisplayMode'pages' | 'custom' | 'default''default'Pagination display mode
positionToolbarAlertBanner'bottom' | 'head-overlay' | 'none' | 'top''bottom'Alert banner position
positionGlobalFilter'none' | 'left' | 'right''left'Global filter position
searchBoxPlaceholderstring'Search'Placeholder text for search box
emptyTableTextstring-Text to display when table is empty

State Props

PropTypeDefaultDescription
paginationPaginationState-Pagination state
sortingSortingState[]Sorting state
rowSelectionRowSelectionState{}Row selection state
columnVisibilityRecord<string, boolean>{}Column visibility state

Event Handler Props

PropTypeDescription
onPaginationChangeOnChangeFn<PaginationState>Called when pagination changes
onSortingChangeOnChangeFn<SortingState>Called when sorting changes
onRowSelectionChangeOnChangeFn<RowSelectionState>Called when row selection changes
onColumnVisibilityChange(e: unknown) => voidCalled when column visibility changes
onColumnOrderChange(e: unknown) => voidCalled when column order changes
onGlobalFilterChange(searchText: string) => voidCalled when global filter changes
onTableContainerScroll(e: React.UIEvent<HTMLDivElement>) => voidCalled when table container scrolls

Render Props

PropTypeDescription
renderDetailPanel({ row }) => JSX.ElementRender detail panel for rows
renderEmptyRowsFallback() => JSX.ElementRender fallback for empty rows
renderTopToolbarCustomActions(e: unknown) => JSX.ElementRender custom top toolbar actions
renderToolbarInternalActions(e: unknown) => JSX.ElementRender internal toolbar actions

Styling Props

PropTypeDefaultDescription
muiPaginationPropsobject-MUI pagination component props
muiTableHeadCellPropsobject-MUI table head cell props
muiTableBodyStylePropsReact.CSSProperties{}Table body cell styles
muiSelectCheckboxPropsCheckboxProps | function-Select checkbox props

Utility Props

PropTypeDescription
getRowId(row: object) => stringFunction to get unique row ID

Examples

Basic Table

import{MuiTable}from'mui-table-react';constBasicTable=()=>{constdata=[{id: 1,name: 'John Doe',age: 30},{id: 2,name: 'Jane Smith',age: 25},];constcolumns=[{accessorKey: 'name',header: 'Name'},{accessorKey: 'age',header: 'Age'},];return<MuiTabledata={data}columns={columns}/>;};

Advanced Table with Features

import{MuiTable}from'mui-table-react';constAdvancedTable=()=>{constdata=[{id: 1,name: 'John Doe',email: 'john@example.com',status: 'Active'},{id: 2,name: 'Jane Smith',email: 'jane@example.com',status: 'Inactive'},];constcolumns=[{accessorKey: 'name',header: 'Name'},{accessorKey: 'email',header: 'Email'},{accessorKey: 'status',header: 'Status'},];return(<MuiTabledata={data}columns={columns}enablePagination={true}enableSorting={true}enableGlobalFilter={true}enableColumnFilters={true}enableRowSelection={true}enableColumnPinning={true}enableColumnOrdering={true}searchBoxPlaceholder='Search users...'emptyTableText='No users found'/>);};

Server-Side Pagination

import{MuiTable}from'mui-table-react';import{useState}from'react';constServerSideTable=()=>{const[pagination,setPagination]=useState({pageIndex: 0,pageSize: 10,});constdata=[{id: 1,name: 'John Doe',email: 'john@example.com'},// ... more data];constcolumns=[{accessorKey: 'name',header: 'Name'},{accessorKey: 'email',header: 'Email'},];return(<MuiTabledata={data}columns={columns}manualPagination={true}rowCount={1000}// Total number of rowspagination={pagination}onPaginationChange={setPagination}/>);};

Development

Prerequisites

  • Node.js 20.x or higher
  • Yarn or npm

Setup

  1. Clone the repository:

    git clone https://github.com/viplatform/mui-table-react.git
    cd mui-table-react
  2. Install dependencies:

yarn install
  1. Start development:
yarn dev

Build

yarn build

Testing

yarn test

Linting

yarn lint
yarn lint:fix

License

MIT

Support

If you have any questions or need help, please open an issue on GitHub.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages