You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MUI X Data Grid无导出按钮禁用属性,如何禁用/移除该按钮?

移除MUI DataGrid的导出按钮

给你两种可行的解决方法:

方法一:通过配置快速隐藏

直接在componentsProps.toolbar中添加showExport: false属性,就能一键隐藏导出按钮,修改后的代码如下:

<DataGrid
    rows={suppliers}
    columns={columns}
    getRowId={(row) => row.supplier_id}
    pageSize={5}
    rowsPerPageOptions={[5]}
    // disableColumnFilter
    // disableColumnSelector
    // disableDensitySelector
    components={{ Toolbar: GridToolbar }}
    componentsProps={{
        toolbar: {
            showQuickFilter: true,
            quickFilterProps: { debounceMs: 500 },
            showExport: false // 添加这一行隐藏导出按钮
        }
    }}
/>

方法二:自定义工具栏(灵活控制功能)

如果你的DataGrid版本不支持showExport属性,可以自定义工具栏组件,只保留需要的功能模块,不包含导出按钮:

import { 
    GridToolbarQuickFilter, 
    GridToolbarColumnsButton, 
    GridToolbarDensitySelector 
} from '@mui/x-data-grid';

// 自定义工具栏,只保留需要的组件
const CustomToolbar = () => (
    <div style={{ display: 'flex', gap: '16px', padding: '8px' }}>
        <GridToolbarQuickFilter debounceMs={500} />
        <GridToolbarColumnsButton />
        <GridToolbarDensitySelector />
        {/* 不引入GridToolbarExport,就不会显示导出按钮 */}
    </div>
);

// 在DataGrid中使用自定义工具栏
<DataGrid
    rows={suppliers}
    columns={columns}
    getRowId={(row) => row.supplier_id}
    pageSize={5}
    rowsPerPageOptions={[5]}
    // disableColumnFilter
    // disableColumnSelector
    // disableDensitySelector
    components={{ Toolbar: CustomToolbar }}
/>

内容的提问来源于stack exchange,提问作者Pusoy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 10:55:21