MRT logoMantine React Table

On This Page

    Column Hiding Feature Guide

    The column hiding feature is enabled by default and allows the user to hide data columns from either the column actions menu or the columns menu.

    Relevant Table Options

    1
    boolean
    true
    MRT Column Hiding Docs
    2
    OnChangeFn<ColumnVisibilityState>
    TanStack Table Column Visibility Docs

    Relevant Column Options

    1
    boolean

    Relevant State

    1
    Record<string, boolean>
    {}
    TanStack Table Column Visibility Docs

    Hide Columns by Default

    You can easily hide columns by default by setting the columnVisibility state or initialState to hide the desired columns by id.
    const table = useMantineReactTable({
    columns,
    data,
    initialState: {
    columnVisibility: {
    firstName: false, //hide firstName column by default
    'mrt-row-expand': false, //hide row expand column by default
    },
    },
    });

    Disable Column Hiding

    If you do not want this feature to be enabled at all, you can disable it by setting the enableHiding prop to false.
    const table = useMantineReactTable({
    columns,
    data,
    enableHiding: false,
    });
    Alternatively, you can disable hiding specific columns by setting the enableHiding column option to false per column.
    If you want to hide certain columns by default, you can specify an column visibility in the initialState.columnVisibility prop. This can also be useful for making the column hiding state persistent.
    DylanMurrayEast DaphneKentucky
    RaquelKohlerColumbusOhio
    ErvinReingerSouth LindaWest Virginia
    BrittanyMcCulloughLincolnNebraska
    BransonFramiCharlestonSouth Carolina
    1-5 of 5
    1
    import { useMemo } from 'react';
    2
    import { MantineReactTable, type MRT_ColumnDef } from 'mantine-react-table';
    3
    4
    const Example = () => {
    5
    const columns = useMemo(
    6
    () =>
    7
    [
    8
    {
    9
    accessorKey: 'firstName',
    10
    enableHiding: false,
    11
    header: 'First Name',
    12
    },
    13
    {
    14
    accessorKey: 'lastName',
    15
    enableHiding: false,
    16
    header: 'Last Name',
    17
    },
    18
    {
    19
    accessorKey: 'address',
    20
    header: 'Address',
    21
    },
    22
    {
    23
    accessorKey: 'city',
    24
    header: 'City',
    25
    },
    26
    {
    27
    accessorKey: 'state',
    28
    header: 'State',
    29
    },
    30
    ] as MRT_ColumnDef<(typeof data)[0]>[],
    31
    [],
    32
    );
    33
    34
    const data = useMemo(
    35
    () => [
    36
    {
    37
    firstName: 'Dylan',
    38
    lastName: 'Murray',
    39
    address: '261 Erdman Ford',
    40
    city: 'East Daphne',
    41
    state: 'Kentucky',
    42
    },
    43
    {
    44
    firstName: 'Raquel',
    45
    lastName: 'Kohler',
    46
    address: '769 Dominic Grove',
    47
    city: 'Columbus',
    48
    state: 'Ohio',
    49
    },
    50
    {
    51
    firstName: 'Ervin',
    52
    lastName: 'Reinger',
    53
    address: '566 Brakus Inlet',
    54
    city: 'South Linda',
    55
    state: 'West Virginia',
    56
    },
    57
    {
    58
    firstName: 'Brittany',
    59
    lastName: 'McCullough',
    60
    address: '722 Emie Stream',
    61
    city: 'Lincoln',
    62
    state: 'Nebraska',
    63
    },
    64
    {
    65
    firstName: 'Branson',
    66
    lastName: 'Frami',
    67
    address: '32188 Larkin Turnpike',
    68
    city: 'Charleston',
    69
    state: 'South Carolina',
    70
    },
    71
    ],
    72
    [],
    73
    );
    74
    return (
    75
    <MantineReactTable
    76
    columns={columns}
    77
    data={data}
    78
    initialState={{ columnVisibility: { address: false } }}
    79
    />
    80
    );
    81
    };
    82
    83
    export default Example;
    1
    import { useMemo } from 'react';
    2
    import { MantineReactTable } from 'mantine-react-table';
    3
    4
    const Example = () => {
    5
    const columns = useMemo(
    6
    () => [
    7
    {
    8
    accessorKey: 'firstName',
    9
    enableHiding: false,
    10
    header: 'First Name',
    11
    },
    12
    {
    13
    accessorKey: 'lastName',
    14
    enableHiding: false,
    15
    header: 'Last Name',
    16
    },
    17
    {
    18
    accessorKey: 'address',
    19
    header: 'Address',
    20
    },
    21
    {
    22
    accessorKey: 'city',
    23
    header: 'City',
    24
    },
    25
    {
    26
    accessorKey: 'state',
    27
    header: 'State',
    28
    },
    29
    ],
    30
    [],
    31
    );
    32
    33
    const data = useMemo(
    34
    () => [
    35
    {
    36
    firstName: 'Dylan',
    37
    lastName: 'Murray',
    38
    address: '261 Erdman Ford',
    39
    city: 'East Daphne',
    40
    state: 'Kentucky',
    41
    },
    42
    {
    43
    firstName: 'Raquel',
    44
    lastName: 'Kohler',
    45
    address: '769 Dominic Grove',
    46
    city: 'Columbus',
    47
    state: 'Ohio',
    48
    },
    49
    {
    50
    firstName: 'Ervin',
    51
    lastName: 'Reinger',
    52
    address: '566 Brakus Inlet',
    53
    city: 'South Linda',
    54
    state: 'West Virginia',
    55
    },
    56
    {
    57
    firstName: 'Brittany',
    58
    lastName: 'McCullough',
    59
    address: '722 Emie Stream',
    60
    city: 'Lincoln',
    61
    state: 'Nebraska',
    62
    },
    63
    {
    64
    firstName: 'Branson',
    65
    lastName: 'Frami',
    66
    address: '32188 Larkin Turnpike',
    67
    city: 'Charleston',
    68
    state: 'South Carolina',
    69
    },
    70
    ],
    71
    [],
    72
    );
    73
    return (
    74
    <MantineReactTable
    75
    columns={columns}
    76
    data={data}
    77
    initialState={{ columnVisibility: { address: false } }}
    78
    />
    79
    );
    80
    };
    81
    82
    export default Example;

    Enable Column Hiding on Display Columns

    By default, column hiding is only enabled on data columns. Display columns, such as mrt-row-numbers, mrt-row-select, etc., do not have column hiding enabled, and their toggle will be disabled. You can turn that back on by setting the enableHiding option to true in the displayColumnsOptions prop.
    const table = useMantineReactTable({
    columns,
    data,
    displayColumnDefOptions: {
    'mrt-row-numbers': {
    enableHiding: true, //now row numbers are hidable too
    },
    },
    });
    See the Display Columns Feature Guide for a more in depth explanation of the displayColumnsOptions prop.
    View Extra Storybook Examples
    You can help make these docs better! PRs are Welcome
    Using Material-UI instead of Mantine?
    Check out Material React Table