MRT logoMaterial React Table

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 Props

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 Some Columns by Default

You can easily hide columns by default by setting the columnVisibility state or initialState to hide the desired columns by id.

<MaterialReactTable
columns={columns}
data={data}
initialState={{ columnVisibility: { firstName: false } }} //hide firstName 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.

<MaterialReactTable columns={columns} data={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

Rows per page

1-5 of 5

Source Code

1import React, { useMemo } from 'react';
2import MaterialReactTable from 'material-react-table';
3
4const 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 //data definitions...
72 ],
73 [],
74 );
75 return (
76 <MaterialReactTable
77 columns={columns}
78 data={data}
79 initialState={{ columnVisibility: { address: false } }}
80 />
81 );
82};
83
84export default Example;
85

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.

<MaterialReactTable
columns={columns}
data={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