我正在使用react-data-table-component.
我有这些专栏:
const columns = [
{
name: 'ID',
selector: 'id',
sortable: true,
},
{
name: 'Place',
selector: 'place',
sortable: true,
},
{
name: 'Created at',
sortable: true,
selector: 'created_at',
cell: row => new Date(row.created_at).toLocaleDateString()
},
{
name: '',
sortable: false,
cell: () => <Button variant="danger" data-tag="allowRowEvents" data-action="delete"><FontAwesomeIcon icon={faTrash} /></Button>,
}
]
在Datatable组件中:
const handleRowClicked = ({id}, e) => {
e.stopPropagation()
const action = e.target.getAttribute('data-action')
switch (action) {
case 'show':
props.openModalDetail(id);
break;
case 'delete':
props.delete(id)
break
default:
return
}
return
}
单击按钮(红色正方形的每个像素)时会监听该事件,但不会在图标本身上监听该事件。
我确实尝试添加data-tag="allowRowEvents"on 图标本身,但没有成功。
我确实尝试添加一个监听器e.currentTarget,但没有成功。
