mui-datatables 隐藏列标题

JWi*_*ley 5 reactjs material-ui

使用materialui-datatables包,有没有办法切换列标题?我看到了覆盖自定义样式的示例,但在站点 api 中找不到选项。

示例位于沙箱中。

我当前的表如下所示:

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}
/>
Run Code Online (Sandbox Code Playgroud)

如果设置为空白,选项选项似乎label会提供此选项,但标头名称仍然保留。我已经尝试了列选项中的各种其他属性,这可能吗?

Ash*_*dav 7

截至目前,使用最新的 MUI 版本,您可以使用slots/slotsProps来自定义 DataGrid。

现已component/componentProps弃用。

更多信息:https ://mui.com/x/react-data-grid/components/#overriding-components

slots道具允许您自定义列标题,您可以返回null以隐藏它。

例子:

<DataGrid
  slots={{
    columnHeaders: () => null,
  }}
/>
Run Code Online (Sandbox Code Playgroud)


Nad*_*ova 2

customHeadRender函数用于自定义标头,要完全删除它,您可以null从中返回:options:{customHeadRender: ()=>null}