MRT logoMaterial React Table

On This Page

    Migrating to Material React Table V2 from V1

    New Feature Highlights

    1. The new optional, but recommended useMaterialReactTable hook that allows you to create the table instance in your own scope.

    2. Greatly improved Editing and new Creating features.

    3. New Row Pinning Features

    4. New Column Filtering 'popover' display mode to give a more "excel-like" filtering experience.

    5. New Autocomplete, Date, and Date Range Filter variants

    6. New Pagination UI options

    7. New Alert Banner UI options and overrides available

    8. New Loading Overlay UI

    9. Improved Table Head Cell Default Styles

    10. Improved Column Sizing and Layout Modes for Column Resizing features

    11. All internal MRT components are now exported for custom headless use cases

    12. New optional createMRTColumnHelper utility function for better TValue/cell.getValue() type inference

    See the full changelog for more details.

    Breaking Changes

    • @mui/x-date-pickers v >=6.15.0 is now a required peer dependency. Install it with:

    $ npm i @mui/x-date-pickers
    • If you use the date picker features, you will also need to import the LocalizationProvider from @mui/x-date-pickers and wrap your app in it. See here for more details.

    import { LocalizationProvider } from '@mui/x-date-pickers';
    import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
    export const App = () => {
    return (
    <ThemeProvider theme={createTheme({})}>
    {/* Add this if using date filter features */}
    <LocalizationProvider dateAdapter={AdapterDayjs}>
    <MyApp />
    </LocalizationProvider>
    </ThemeProvider>
    );
    };
    • MaterialReactTable is now a named export instead of a default export. Use curly braces to import it.

    - import MaterialReactTable from 'material-react-table'
    + import { MaterialReactTable, useMaterialReactTable } from 'material-react-table'
    • There is no longer a tableInstanceRef prop. It has been replaced by the useMaterialReactTable hook, which is way easier to use. It will also be recommended that all table options should be passed to the new useMaterialReactTable hook instead as props to the <MaterialReactTable /> component. See below for more details.

    Renamed Props/Options

    • editingMode -> editDisplayMode

    • rowNumberMode -> rowNumberDisplayMode

    • enablePinning -> enableColumnPinning and enableRowPinning

    • virtualizerInstanceRef split into columnVirtualizerRef and rowVirtualizerRef

    • virtualizerProps split into columnVirtualizerOptions and rowVirtualizerOptions

    • columnVirtualizerProps -> columnVirtualizerOptions

    • rowVirtualizerProps -> rowVirtualizerOptions

    • muiTablePaginationProps -> muiPaginationProps

    • muiTableBodyCellCopyButtonProps -> muiCopyButtonProps

    • muiTableBodyCellEditTextFieldProps -> muiEditTextFieldProps

    • muiTableBodyCellSkeletonProps -> muiSkeletonProps

    • muiTableBodyRowDragHandleProps -> muiRowDragHandleProps

    • muiTableDetailPanelProps -> muiDetailPanelProps

    • muiTableHeadCellColumnActionsButtonProps -> muiColumnActionsButtonProps

    • muiTableHeadCellDragHandleProps -> muiColumnDragHandleProps

    • muiTableHeadCellFilterCheckboxProps -> muiFilterCheckboxProps

    • muiTableHeadCellFilterTextFieldProps -> muiFilterTextFieldProps

    • muiTableHeadCellFilterSliderProps -> muiFilterSliderProps

    • MRT_FilterFnsState -> MRT_ColumnFilterFns

    • MaterialReactTableProps -> MRT_TableOptions

    useMaterialReactTable

    Passing all table options as props to <MaterialReactTable /> will still work, but there is a new and better way to define table options with the useMaterialReactTable hook.

    For example, here is a classic example for how to use Material React Table in V1 (still works in V2):

    import { MaterialReactTable } from 'material-react-table';
    export const MyTableComponent = () => {
    // const tableInstanceRef = useRef(); //deprecated
    return (
    //Defining table options as props to <MaterialReactTable /> still works (as long as you don't also pass in a table prop)
    <MaterialReactTable
    columns={columns}
    data={data}
    enableRowSelection //table options as props
    // tableInstanceRef={tableInstanceRef} //deprecated
    />
    );
    };

    But now, you can define all table options in the useMaterialReactTable.

    import {
    MaterialReactTable,
    useMaterialReactTable,
    } from 'material-react-table';
    export const MyTableComponent = () => {
    const table = useMaterialReactTable({
    columns,
    data,
    enableRowSelection: true, //table options as options to this hook
    });
    return (
    <MaterialReactTable
    table={table} //only pass in table instead of all table options
    />
    );
    };

    Why is useMaterialReactTable Better?

    There are a few reasons why having full access to the table instance is better than having MRT create it under the hood for you.

    1. No more need for a confusing tableInstanceRef prop that doesn't properly cause re-renders when the table instance changes. Now any component that consumes the table instance will properly re-render when the table instance changes.

    2. Allows for you to not need to use all of Material React Table's components. For example, if you only want to use the Table component with no TableContainer or Toolbars, you can simply import a different component from Material React Table.

    import { MRT_Table, useMaterialReactTable } from 'material-react-table';
    export const MyTableComponent = () => {
    const table = useMaterialReactTable({
    columns,
    data,
    enableRowSelection: true,
    });
    const selectedRows = table.getSelectedRowModel().rows;
    console.log(selectedRows);
    return (
    //this internal sub-component does not include the Paper, TableContainer, or Toolbars (lighter weight)
    <MRT_Table table={table} />
    );
    };

    Is anything missing from this v2 migration guide? Make a PR or join the Discord to discuss.