Skip to content

Data grid - Column visibility

Define which columns are visible.

By default, all the columns are visible. The column's visibility can be switched through the user interface in two ways:

  • By opening the column menu and clicking the Hide menu item.
  • By clicking the Columns menu and toggling the columns to show or hide.

You can prevent the user from hiding a column through the user interface by setting the hideable in GridColDef to false.

In the following demo, the "username" column cannot be hidden.

username
age
desk
@MUI
38
D-546
@MUI-X
25
D-042

Rows per page:

1–2 of 2

Press Enter to start editing

Initialize the visible columns

To initialize the visible columns without controlling them, provide the model to the initialState prop.

<DataGrid
  initialState={{
    columns: {
      columnVisibilityModel: {
        // Hide columns status and traderName, the other columns will remain visible
        status: false,
        traderName: false,
      },
    },
  }}
/>
Desk
Commodity
Trader Name
Trader Email
Quantity
Filled Quantity
Is Filled
Unit Price

Rows per page:

0–0 of 0

Controlled visible columns

Use the columnVisibilityModel prop to control the visible columns. You can use the onColumnVisibilityModelChange prop to listen to the changes to the visible columns and update the prop accordingly.

<DataGrid
  columnVisibilityModel={{
    // Hide columns status and traderName, the other columns will remain visible
    status: false,
    traderName: false,
  }}
/>
Desk
Commodity
Trader Name
Trader Email
Quantity
Filled Quantity
Is Filled
Unit Price

Rows per page:

0–0 of 0

Press Enter to start editing

Column visibility panel

The column visibility panel can be opened through the grid toolbar. To enable it, you need to add Toolbar: GridToolbar to the grid components prop.

The user can then choose which columns are visible using the Columns button.

No rows
Desk
Commodity
Trader Name
Trader Email
Quantity
Filled Quantity
Is Filled
Status

Rows per page:

0–0 of 0

Press Enter to start editing

Column hide property (deprecated)

Before the introduction of the columnVisibilityModel, the columns could be hidden by setting the hide property in GridColDef to true. This method still works but will be removed on the next major release.

username
desk
@MUI
D-546
@MUI-X
D-042

Rows per page:

1–2 of 2

Press Enter to start editing