javascript - antd table actions and onrow function - Stack Overflow

While clicking actions in antd table onRow click action is also initiated. How can i solve these proble

While clicking actions in antd table onRow click action is also initiated. How can i solve these problem

key = (selectedRowKeys) => {
console.log('selected values', selectedRowKeys);a
   }
action = () => {
console.log('received in actions')
}

Table code:

<Table
   onRowClick={this.key}
   loading={this.state.loading}
   dataSource={data}
   bordered="true"
>
<Column
 title="ID"
 dataIndex="id"
 key="id"
 width="100"
 zIndex="-1"
/>
<Column
 title="Action"
 key="action"
 width="200"
 render={(text, record) => (
   <span style={{ zIndex: '-1' }}>

     <a href="javascript:;" onClickCapture={this.action}>ACTION</a>
   </span>
 )}
/>
</Table>

while clicking the actions in the table the onclick function is also initiated, how to solve this im new to reactjs

While clicking actions in antd table onRow click action is also initiated. How can i solve these problem

key = (selectedRowKeys) => {
console.log('selected values', selectedRowKeys);a
   }
action = () => {
console.log('received in actions')
}

Table code:

<Table
   onRowClick={this.key}
   loading={this.state.loading}
   dataSource={data}
   bordered="true"
>
<Column
 title="ID"
 dataIndex="id"
 key="id"
 width="100"
 zIndex="-1"
/>
<Column
 title="Action"
 key="action"
 width="200"
 render={(text, record) => (
   <span style={{ zIndex: '-1' }}>

     <a href="javascript:;" onClickCapture={this.action}>ACTION</a>
   </span>
 )}
/>
</Table>

while clicking the actions in the table the onclick function is also initiated, how to solve this im new to reactjs

Share Improve this question edited Aug 21, 2019 at 11:23 Andronicus 26.1k18 gold badges54 silver badges91 bronze badges asked Aug 21, 2019 at 7:50 Theresa joyTheresa joy 371 silver badge3 bronze badges 1
  • 2 Try using e.stopPropogation(). It really depends on which event gets called first. Another issue is that you are using a link, rather than a button. Consider using antd's <Button type="link"> – Kobe Commented Aug 21, 2019 at 7:54
Add a ment  | 

2 Answers 2

Reset to default 4

This is a classic case of event bubbling.

Try stopping the event propagation in the following way:

action = (event) => {
  event.stopPropagation();
  console.log('received in actions');
}

This should capture the event and stop it from propagating to the parent event handler.

 <Table 
      loading={this.state.loading}
      dataSource={data}
      bordered="true"
      onRow={(r) => ({
         onClick: () => console.log(r.key),
      })}
 />

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745043165a4607933.html

相关推荐

  • javascript - antd table actions and onrow function - Stack Overflow

    While clicking actions in antd table onRow click action is also initiated. How can i solve these proble

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信