【问题标题】:MUI Datagrid rendercell getValue return undefinedMUI Datagrid rendercell getValue 返回未定义
【发布时间】:2023-03-21 04:47:02
【问题描述】:

由于我将代码推送到生产环境,我不能再在 renderCell 中调用 getValue

环境和dev一样

这里是列定义:

const columns = [
        {
            field: 'edit',
            headerName: 'Edit',
            sortable: false,
            width: 78,
            renderCell: (params) => (
                <div>
                 <EditProduct defaultCats={props.defaultCats} prodId={params.getValue('id')} productIdGL={params.getValue('productId')} />
                </div>  
              ),
            align: "left",
        },
        {
            field: 'active',
            headerName: 'Off / On',
            width: 104,
            renderCell: (params) => (
                <div><CustomSwitch
                    checked={Boolean(params.value)}
                    onChange={() => myswitch(params.getValue('id'), Boolean(params.value))}
                    name="switch-"
                    inputProps={{ 'aria-label': 'primary checkbox' }}
                ></CustomSwitch>
                </div>  
              ),
              align: "left",
        },
        { field: 'category_name', headerName: 'Catégorie', width: 120 },
        { field: 'item_name', headerName: 'Nom du produit', width: 220 },
        {
          field: 'price',
          headerName: 'Prix de vente',
          type: 'number',
          width: 140,

        },
        {
          field: 'profit',
          headerName: 'Profit par vente',
          type: 'number',
          width: 160,
          alt: 'Test'
        },
        { field: 'type', headerName: 'Type', width: 90 },
        { field: 'id', headerName: '#', width: 80 },
      ];

错误:

Unhandled Runtime Error
TypeError: Cannot read property 'undefined' of undefined

任何帮助感谢,因为这个错误只发生在生产中

mui 核心:4.11.4 mui-datagrid: 4.0.0-alpha.26

【问题讨论】:

    标签: material-ui getvalue


    【解决方案1】:
    params.getValue(params.id, 'id') || ''
    
    

    代替

    params.getValue('id')
    

    【讨论】:

      猜你喜欢
      • 2023-02-01
      • 2022-12-15
      • 2022-12-23
      • 2022-07-20
      • 2019-11-17
      • 1970-01-01
      • 2018-02-08
      • 2016-11-18
      • 1970-01-01
      相关资源
      最近更新 更多