【问题标题】:Click on a row to open a modal with the row's data单击一行以打开包含该行数据的模式
【发布时间】:2018-11-03 03:16:34
【问题描述】:

我正在使用 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
       />

按钮点击后的动作

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

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

【问题讨论】:

    标签: reactjs modal-dialog react-table


    【解决方案1】:

    为什么你用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});
      }; 
    

    【讨论】:

      猜你喜欢
      • 2016-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-12
      相关资源
      最近更新 更多