Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mui-datatables hide column headers

Using the materialui-datatables package, is there a way to toggle the column headers? I see examples for overriding the custom styling but can't find an option in the site api.

Examples are here in a sandbox.

My current table looks like this:

const columns = [
        {
            name: "Question",
            label: "",
            options: {
                someOptionToToggle: true
            },
        }, 
        {
            name: "Answer",
            label: ""        
        }
    ]; 
 const options = {
        filter: false,
        responsive: "scroll",
        download: false,
        sort: false,
        selectableRows: false,
        print: false,
        viewColumns: false,
        searchOpen: true,
        searchText: searchText,
        search: false,
        customSearchRender: () => null
    }; 
<MUIDataTable
      title={""}
      data={faqData}
      columns={columns}
      options={options}
/>

It would seem that the option label option would provide this if set to blank, but the header name remains. I've tried various other attributes in the column options, is this possible?

like image 721
JWiley Avatar asked Mar 23 '26 08:03

JWiley


2 Answers

As of now, with latest MUI version you can make use of the slots/slotsProps to customize the DataGrid.

The component/componentProps is now deprecated.

More information: https://mui.com/x/react-data-grid/components/#overriding-components

The slots props allows you to customize the column header where you can return null to hide it.

Example:

<DataGrid
  slots={{
    columnHeaders: () => null,
  }}
/>
like image 173
Ashish Yadav Avatar answered Mar 24 '26 22:03

Ashish Yadav


Use columnHeaderHeight https://mui.com/x/api/data-grid/data-grid/#DataGrid-prop-columnHeaderHeight

Example:

<DataGridPro
  columnHeaderHeight={0}
like image 20
Fábio Miranda Avatar answered Mar 24 '26 22:03

Fábio Miranda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!