Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide a column in a MUI X Data Grid?

I don't want to show the id field of my table. I use "@mui/x-data-grid": "^5.6.1" version. Here is my code:

import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';


const columns = [
    { field: 'id', headerName: 'ID', width: 50},
    { field: 'testName', headerName: 'Test Name', width: 120,},
    { field: 'testDate', headerName: 'Test Date', width: 160 },
];

export default function DataTable(props) {

    const rows = [id:1, testName:"test", testDate:"23/03/2022"];

    return (
        <div id="resultTable" >
            <DataGrid
                rows={rows}
                columns={columns}
                pageSize={5}
                rowsPerPageOptions={[5]}

            />
        </div>
    );
}

The Id column can be hidden or display:none. I tried to use

display: false

Or:

hidden: true

And I also tried:

options: {display: false, filter: false,}, but it didn’t work.

like image 277
Burak Algur Avatar asked Sep 11 '25 17:09

Burak Algur


1 Answers

According to MUI X documentation, hide: true is now deprecated.

Instead you should use the Column Visibility Model.

Example from the documentation:

<DataGrid
  initialState={{
    columns: {
      columnVisibilityModel: {
        // Hide columns status and traderName, the other columns will remain visible
        status: false,
        traderName: false,
      },
    },
  }}
/>
like image 194
Robinson Avatar answered Sep 14 '25 06:09

Robinson