简体   繁体   English

单击单行高亮显示React表。 禁用多选

[英]React-table on click single row highlight. Disable multiple select

I am working on small function add, edit, delete function in React-table. 我正在研究React表中的小功能添加,编辑,删除功能。 my codes are running. 我的代码正在运行。 My issue if the user clicks on the row it gets selected at the same time if you click on another row its get selected but it doesn't disable the previously selected row. 我的问题是,如果用户单击另一行,则会同时选中该行,但不会禁用先前选择的行。 Basically, the user can select one row at the time. 基本上,用户可以一次选择一行。 Disable multiple select. 禁用多选。

Also, it would be great if anyone can review my add, update, delete function. 另外,如果任何人都可以查看我的添加,更新,删除功能,那将是很好的。 Whether it is right approach or not. 是否正确的方法。

Running Code 运行代码 单高亮行

Fixed 固定

  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 {};
        }
      }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM