首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >mui数据表无法读取未定义的属性(读取“下载”)

mui数据表无法读取未定义的属性(读取“下载”)
EN

Stack Overflow用户
提问于 2022-07-19 12:49:32
回答 1查看 379关注 0票数 0

我用的是"react": "^17.0.2","mui-datatables": "^4.2.2",

我需要下载(导出)数据中没有显示的数据。

这是我代码的一部分:

代码语言:javascript
运行
复制
    [
    // ..... other columns
    {
      label: "Détail IIG",
      name: "reference",
      options: {
        download: false,
        customBodyRender: (value) => {
          if (currentUserId === value.user.id) {
            if (value.calculated) {
              return (
                <Tooltip title="les résultats IIG de votre dossier sont disponibles">
                  <Link
                    className="custom-green-iig-link"
                    to={`/${value.slug}/project/iig`}
                  >
                    <FontAwesomeComponent
                      icon={faEye}
                      size="lg"
                      color="white"
                    />
                  </Link>
                </Tooltip>
              );
            } else {
              return null;
            }
          } else {
            if (value.calculated) {
              return (
                <Tooltip title="Les résultats IIG de ce dossier sont disponibles">
                  <Link
                    className="custom-green-iig-link"
                    to={`/${value.slug}/project/iig`}
                  >
                    <FontAwesomeComponent
                      icon={faEye}
                      size="lg"
                      color="white"
                    />
                  </Link>
                </Tooltip>
              );
            } else {
              return null;
            }
          }
        },
        setCellHeaderProps: (value) => ({
          style: {
            fontWeight: "bold",
            textAlign: "center",
            whiteSpace: "nowrap",
          },
        }),
        setCellProps: (value) => ({
          style: {
            textAlign: "center",
          },
        }),
      },
    },
    {
      name: "pilierE",
      options: {
        empty: false,
        download: true,
        filter: false,
        sort: false,
        display: false,
        viewColumns: false,
      },
    },
  ];

这是onDownload函数:

代码语言:javascript
运行
复制
onDownload: (buildHead, buildBody, columns, rows) => {
  console.log(columns);
  const all = [];
  if (selectedRows.length) {
    selectedRows.forEach((row, index) => {
      let object = {
        index: index,
        data: row,
      };
      console.log("OBJ");
      all.push(object);
    });
    return "\uFEFF" + buildHead(columns) + buildBody(all);
  } else {
    setOpenExportAlert(true);
    return false;
  }
},

因此,我使用download: true,display: false,隐藏显示列,并启用、禁用下载。

目前,我得到了这个错误:

代码语言:javascript
运行
复制
> utils.js:91 Uncaught TypeError: Cannot read properties of undefined
>     (reading 'download')
>     at utils.js:91:1
>     at Array.filter (<anonymous>)
>     at utils.js:87:1
>     at Array.reduce (<anonymous>)
>     at i (utils.js:84:1)
>     at Object.onDownload (Home.js:342:1)
>     at buildCSV (utils.js:105:1)
>     at createCSVDownload (utils.js:130:1)
>     at TableToolbar.js:193:1
>     at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)

如何纠正此错误?

EN

回答 1

Stack Overflow用户

发布于 2022-07-19 13:05:12

代码语言:javascript
运行
复制
I fix the problem, i have filterOptions like this , so i set useDisplayedColumnsOnly and useDisplayedRowsOnly to true instead of false

  downloadOptions: {
          filename: "IIG-EXPORT.csv",
          separator: ";",
          filterOptions: {
            useDisplayedColumnsOnly: false, // it was true
            useDisplayedRowsOnly: false, // it was true
          },
        },
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73037229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档