简体   繁体   English

如何在反应表中为单行设置 2 个不同的事件

[英]how to have 2 different events for a single row in react-table

I am using react table v6, I have a button in each row,on click of button I want to perform some operation and on click of row I need to perform some other operation.我正在使用 react table v6,我在每一行都有一个按钮,单击按钮我想执行一些操作,单击行我需要执行一些其他操作。 I am using getTrProps() component decorator to perform the on click operation on row but after using this the click on button is also considered as a row click and it is performing the operation of row click.我正在使用 getTrProps() 组件装饰器对行执行单击操作,但在使用此按钮后,单击按钮也被视为行单击,它正在执行行单击操作。

    <ReactTable
     data={rowData}
     sortable={true}
     showPagination={true}
     getTrProps={(state, rowInfo) => {
      if (rowInfo && rowInfo.row) {
        return {
          onClick: e => {
            setState(true);
            setData(rowData[rowInfo.index].shortName);
          }

        };
      } else {
        return {};
      }
    }}
    columns={[
      { Header: "Name", accessor: "displayName" },
      {
        Header: "",

        Cell: (
          <DeleteServiceModel
            btnName={"Delete"}
            comp={"product"}
            size="sm"
            data={""}
            {...props}
          />
        )
      }
    ]}
    defaultPageSize={5}
    className="-striped -highlight"
 />

这是桌子设计

This is because your event is getting propagated.这是因为您的事件正在传播。

e.stopPropagation()

to stop the propagation inside the on Click function of your button.在单击按钮的 function 内停止传播。

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

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