【问题标题】:Adding modal popup to cells in ant design table向 ant 设计表中的单元格添加模式弹出窗口
【发布时间】:2021-07-16 11:31:24
【问题描述】:

我正在尝试将模态添加到 ant 设计表中的列中,因此当我单击单元格中的值时,会弹出一个模态。但是当我尝试添加 onCell 属性时,我似乎无法使其工作。我应该为 onClick 函数写什么?我试过 this.showModal;但它不起作用。

这是设置列属性的代码:

for (let i = 0; i < 1; i++) {
  columns.push({
    title: "2021" + (i + 1 + 5) + "F",
    dataIndex: "a" + (i + 2),
    align: "right",
    render: (text) => <a href="#">{text}</a>,
    onCell: (record, rowIndex) => {
      return {
        onClick: () => {
          //insert show modal function
        }
      };
    }
  });
}

这是一个工作沙箱: https://codesandbox.io/s/dynamic-settings-antd4167-forked-0kcu0

【问题讨论】:

    标签: javascript reactjs antd react-table react-modal


    【解决方案1】:

    你在columns 中使用了onCell 吗?我试过了,效果很好

    const tableColumns = columns.map((item) => ({
          ...item,
          ellipsis: state.ellipsis,
          onCell: (data, index) => {
            return {
              onClick: (event) => {
                console.log("click");
                this.showModal()
              }, // click row
            };
          }
        }));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-08
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 2020-08-17
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多