MRT logoMantine React Table

On This Page

    Click to Copy Feature Guide

    Mantine React Table has an easy-to-implement feature that allows a user to copy a cell's value to the clipboard.

    Relevant Table Options

    #
    Prop Name
    Type
    Default Value
    More Info Links
    1booleanfalseMRT Click to Copy Docs
    2UnstyledButtonProps | ({ cell, column, row, table }) => UnstyledButtonPropsMantine UnstyledButton Docs

    Relevant Column Options

    #
    Column Option
    Type
    Default Value
    More Info Links
    1booleanMRT Click to Copy Docs
    2UnstyledButtonProps | ({ cell, column, row, table }) => UnstyledButtonPropsMantine UnstyledButton API

    Enable Click to Copy Per Column

    Most likely, there will just be a couple columns that you want to enable click to copy for. You can do this by setting the enableClickToCopy option to true per column on the column definition.

    const columns = [
      //...
      {
        accessorKey: 'email',
        header: 'Email',
        enableClickToCopy: true,
      },
      //...
    ];

    Enable Click to Copy For All Cells

    Alternatively, you can enable click to copy globally by setting the enableClickToCopy table option to true. You could then opt out per column by setting the enableClickToCopy option to false on the column definition.

    const table = useMantineReactTable({
      columns,
      data,
      enableClickToCopy: true,
    });

    Customize Copy Buttons

    The click to copy feature is built on top of the Mantine UnstyledButton and CopyButton components. You can customize the copy button by passing in the mantineCopyButtonProps table or column option.

    const table = useMantineReactTable({
      columns,
      data,
      enableClickToCopy: true,
      mantineCopyButtonProps: {
        style: { width: '100%' },
        leftIcon: <ContentCopy />,
      },
    });

    Click to Copy Example

    First Name
    Last Name
    Email
    City
    DylanMurray
    RaquelKohler
    ErvinReinger
    BrittanyMcCullough
    BransonFrami

    Rows per page

    1-5 of 5

    import '@mantine/core/styles.css';
    import '@mantine/dates/styles.css'; //if using mantine date picker features
    import 'mantine-react-table/styles.css'; //make sure MRT styles were imported in your app root (once)
    import { useMemo } from 'react';
    import {
      MantineReactTable,
      useMantineReactTable,
      type MRT_ColumnDef,
    } from 'mantine-react-table';
    import { data, type Person } from './makeData';
    
    const Example = () => {
      const columns = useMemo<MRT_ColumnDef<Person>[]>(
        () => [
          {
            accessorKey: 'firstName',
            header: 'First Name',
          },
          {
            accessorKey: 'lastName',
            header: 'Last Name',
          },
          {
            accessorKey: 'email',
            header: 'Email',
            enableClickToCopy: true,
          },
          {
            accessorKey: 'city',
            header: 'City',
            enableClickToCopy: true,
          },
        ],
        [],
      );
    
      const table = useMantineReactTable({
        columns,
        data,
      });
    
      return <MantineReactTable table={table} />;
    };
    
    export default Example;

    View Extra Storybook Examples