【问题标题】:MUI DataGrid Error: TypeError: Cannot read properties of undefined (reading 'MuiDataGrid')MUI DataGrid 错误:TypeError:无法读取未定义的属性(正在读取“MuiDataGrid”)
【发布时间】:2021-11-30 13:17:46
【问题描述】:

我试图更改我的 DataGrid MUI 参数的默认参数的语言,由于某种原因,当我尝试添加 localeText 时遇到错误,我正在按照他们资源中的确切说明进行操作页面,Locale Text

这是它显示的错误:

这就是我正在做的(只是添加相关代码):

import { DataGrid, esES} from '@mui/x-data-grid';

<DataGrid 
  localeText={esES.props.MuiDataGrid.localeText}
  rows={estudiantes}
  columns={columns}
  autoPageSize 
/>

【问题讨论】:

    标签: reactjs datagrid material-ui locale


    【解决方案1】:

    我认为文档已经过时,如果您记录 esES 变量,您将知道在 localeText 中放入什么:

    <DataGrid
      {...data}
      localeText={esES.components.MuiDataGrid.defaultProps.localeText}
      components={{
        Toolbar: GridToolbar
      }}
    />
    

    在 v4 中,可以使用 esES.props.MuiDataGrid.localeText,因为这是您覆盖默认道具的方式:

    const theme = createTheme({
      props: {
        MuiDataGrid: {
          localeText: {...},
        },
      },
    });
    

    在 v5 中,它是 esES.components.MuiDataGrid.defaultProps.localeText,因为默认的 props 路径更改为:

    const theme = createTheme({
      components: {
        MuiDataGrid: {
          defaultProps: {
            localeText: {...},
          },
        },
      },
    });
    

    现场演示

    参考

    【讨论】:

    • 哦,非常感谢它成功了
    • 非常感谢这对我有用,但我想知道为什么没有更新文档?
    猜你喜欢
    • 1970-01-01
    • 2022-12-24
    • 2023-02-26
    • 2022-11-06
    • 2022-07-06
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    相关资源
    最近更新 更多