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

Material UI:如何禁用DataGrid组件的底部滚动条?

解决方案

可以试试以下几种方法:

  • 检查容器高度限制:确保DataGrid的父元素没有设置固定高度或overflow: auto这类属性,autoHeight需要父容器能自适应高度才能正常生效。
  • 通过CSS强制隐藏滚动条:自定义样式覆盖DataGrid的滚动行为,比如:
    import { DataGrid } from '@mui/x-data-grid';
    import { styled } from '@mui/material/styles';
    
    const StyledDataGrid = styled(DataGrid)`
      /* 隐藏所有滚动条 */
      & .MuiDataGrid-main {
        overflow: hidden !important;
      }
      /* 仅隐藏底部横向滚动条 */
      & .MuiDataGrid-window {
        overflow-x: hidden !important;
      }
    `;
    
    // 使用自定义组件
    <StyledDataGrid
        rows={rows}
        columns={columns}
        autoHeight={true}
        rowsPerPageOptions={[5]}
        pageSize={5}
        disableSelectionOnClick
        density="compact"
        hideFooterPagination={true}
        hideFooter={true}
        showCellRightBorder={true}
        showColumnRightBorder={true}
    />
    
  • 调整列宽避免溢出:如果是列总宽度超出容器导致的横向滚动条,可以给列设置flex: 1让列自适应容器宽度,或者手动设置合适的width属性,避免列宽总和超过容器宽度。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 21:10:26