【问题标题】:React-table on click single row highlight. Disable multiple select单击单行突出显示时的反应表。禁用多选
【发布时间】:2019-04-27 15:24:11
【问题描述】:

我正在研究 React-table 中的小函数添加、编辑、删除函数。 我的代码正在运行。 我的问题是,如果用户单击它同时被选中的行,如果您单击另一行它被选中,但它不会禁用先前选择的行。基本上,用户一次可以选择一行。禁用多选。

另外,如果有人可以查看我的添加、更新、删除功能,那就太好了。不管是不是正确的方法。

Running Code

【问题讨论】:

    标签: javascript reactjs react-table


    【解决方案1】:

    固定

      getTrProps={(state, rowInfo) => {
            if (rowInfo && rowInfo.row) {
              return {
                onClick: e => {
                  console.log("inside");
    
                  if (rowInfo.index != this.state.rowEdit) {
                    this.setState({
                      rowEdit: rowInfo.index,
                      selectedRowIndex: rowInfo.original,
                      selectionChanged: this.state.selectionChanged
                        ? false
                        : true
                    });
                  } else {
                    this.setState({
                      rowEdit: null
                    });
                  }
                  console.log(rowInfo.index);
                  console.log(this.state.rowEdit);
                },
                style: {
                  background:
                    rowInfo.index === this.state.rowEdit ? "#00afec" : "white",
                  color:
                    rowInfo.index === this.state.rowEdit ? "white" : "black"
                }
              };
            } else {
              return {};
            }
          }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-11
      • 2017-09-21
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      相关资源
      最近更新 更多