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.
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,
      },
    },
  }}
/>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With