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

MUI X DataGrid自定义样式需求:覆盖模板预设样式实现目标布局

需求与问题

我使用的模板自带DataGrid预设样式类,会作用于模板内所有DataGrid组件。我需要通过@emotion/styled创建自定义样式的DataGrid组件,以实现目标布局,但当前渲染效果未达到预期。

依赖项:@emotion/styled

自定义StyledDataGrid代码
const StyledDataGrid = styled(DataGrid)(({ theme }) => ({
  root: {
    '& .MuiDataGrid-renderingZone': {
      maxHeight: 'none !important',
    },
    '& .MuiDataGrid-cell': {
      lineHeight: 'unset !important',
      maxHeight: 'none !important',
    },
    '& .MuiDataGrid-root .MuiDataGrid-cell ': {
      maxHeight: 'none !important',
      minHeight: 'mpne !important' // 注:此处存在拼写错误,应为"none"
    },
    '& .MuiDataGrid-virtualScrollerRenderZone .MuiDataGrid-row ' : {
        maxHeight: 'none !important',
    }
  },
}));
DataGrid组件使用代码
<StyledDataGrid
  rows={(temp.length === count ? rows : temp)}
  columns={columns}
  pageSize={20}
  autoHeight
  rowHeight={465}
  getRowSpacing={getRowSpacing}
  disableSelectionOnClick
  getRowClassName={(params) => `super-app-theme--${params.row.qa_status} && ${params.row.pkg_status}`}
  components={{ Toolbar: GridToolbar }}
/>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 19:57:18