Minimal Example
Material React Table gives you a lot out of the box, but it's also easy to turn off any features that you do not need.
Every feature has an enable...
table option that let's you turn it on or off.
For example, you can turn off sorting or hide the top or bottom toolbars if you want.
First Name | Last Name | Address | City | State |
---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio |
Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia |
Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska |
Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
1import { useMemo } from 'react';2import {3 MRT_Table, //import alternative sub-component if we do not want toolbars4 type MRT_ColumnDef,5 useMaterialReactTable,6} from 'material-react-table';7import { data, type Person } from './makeData';89export const Example = () => {10 const columns = useMemo<MRT_ColumnDef<Person>[]>(11 //column definitions...36 );3738 const table = useMaterialReactTable({39 columns,40 data, //data must be memoized or stable (useState, useMemo, defined outside of this component, etc.)41 enableColumnActions: false,42 enableColumnFilters: false,43 enablePagination: false,44 enableSorting: false,45 mrtTheme: (theme) => ({46 baseBackgroundColor: theme.palette.background.default, //change default background color47 }),48 muiTableBodyRowProps: { hover: false },49 muiTableProps: {50 sx: {51 border: '1px solid rgba(81, 81, 81, .5)',52 caption: {53 captionSide: 'top',54 },55 },56 },57 muiTableHeadCellProps: {58 sx: {59 border: '1px solid rgba(81, 81, 81, .5)',60 fontStyle: 'italic',61 fontWeight: 'normal',62 },63 },64 muiTableBodyCellProps: {65 sx: {66 border: '1px solid rgba(81, 81, 81, .5)',67 },68 },69 renderCaption: ({ table }) =>70 `Here is a table rendered with the lighter weight MRT_Table sub-component, rendering ${table.getRowModel().rows.length} rows.`,71 });7273 //using MRT_Table instead of MaterialReactTable if we do not need any of the toolbar components or features74 return <MRT_Table table={table} />;75};7677export default Example;78
View Extra Storybook Examples