reactjs - 单击一行以打开包含该行数据的模式

标签 reactjs modal-dialog react-table

我正在使用 react-table,这是我的表格:

<ReactTable
          data={this.props.data}
          columns={[
            {
              Header: "id",
              accessor: "id",
              width: 50
            },
            {
              Header: "Name",
              accessor: "name",
              width: 200
            },
            {
              Header: "",
              id: "id",
              Cell: ({ row }) => (
                <button onClick={e => this.handleButtonClick(e, row)}>
                  Click Me
                </button>
              )
            }
          ]}
          defaultPageSize={10}
          showPaginationBottom
       />

点击按钮后的 Action

handleButtonClick = (e, row) => {
    this.setState({ visible: true});
    return 
       <Modal 
          title="title" 
          visible={this.state.visible}
        >
        // show data here
    </Modal>
  }; 

这就是我现在的工作方式,但是没有显示模态。谁能帮我这个?我做错了什么?

最佳答案

为什么使用 handleButtonClick 函数返回模态而不是使用 ReactTable 添加它

<ReactTable
          data={this.props.data}
          columns={[
            {
              Header: "id",
              accessor: "id",
              width: 50
            },
            {
              Header: "Name",
              accessor: "name",
              width: 200
            },
            {
              Header: "",
              id: "id",
              Cell: ({ row }) => (
                <button onClick={e => this.handleButtonClick(e, row)}>
                  Click Me
                </button>
              )
            }
          ]}
          defaultPageSize={10}
          showPaginationBottom
       />

      {this.state.visible && <Modal 
          title="title" 
          visible={this.state.visible}
        >
        // show data here
    </Modal>}

handleButtonClick = (e, row) => {
    this.setState({ visible: true});
  }; 

关于reactjs - 单击一行以打开包含该行数据的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50500115/

相关文章:

javascript - 如何不使用 Webpack 解析路径?

javascript - 如何将来自 setInterval 的数据推送到数组中

reactjs - 网格还是 Flexbox?如果使用 react-semantic-ui

jquery - ASP.NET MVC 模式对话框/弹出窗口最佳实践

javascript - 调整 react 表大小

node.js - 使用 UTF-8 的 Axios setRequestHeader 方法

jquery - 使用 Bootstrap Modal 确认操作

css - 通过 ID 将 CSS(通过 LESS)应用于模式框不起作用

react-table - 列显示属性是否在最新的 react-table v7 中停止工作?

javascript - 表详细信息的 Prop