react antd tabel tooltip 点击复制

jsx语法  + document.execCommand('copy')

在render中 ,onclick ={copy} ,如果没有tooltip,可以直接进行点击事件,方法中的判断可以不写

 //点击复制

  const copy = (e) => {

    const range = document.createRange()

    window.getSelection()?.removeAllRanges()

    //这个地方有时候会进行省略,做下判断如果是省略部分,就直接return,否则复制

    if (e.target.innerText.indexOf('...') != -1) {

      return

    } else {

      range.selectNode(e.target)

    }

    window.getSelection()?.addRange(range)

    const sucful = document.execCommand('copy')

    if (sucful) {

      message.success('复制成功')

    }

  }

效果图

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您需要在 Ant Design 的 Table 组件中嵌套 Table 组件,可以使用 `expandedRowRender` 属性来实现。下面是一个示例代码: ```jsx import React from 'react'; import { Table } from 'antd'; const columns = [ { title: 'Name', dataIndex: 'name' }, { title: 'Age', dataIndex: 'age' }, { title: 'Address', dataIndex: 'address' }, ]; const data = [ { key: 1, name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', children: [ { key: 11, name: 'Jim Green', age: 42, address: 'London No. 2 Lake Park', }, { key: 12, name: 'Joe Black', age: 32, address: 'Sidney No. 3 Lake Park', }, ], }, { key: 2, name: 'Jim Green', age: 42, address: 'London No. 2 Lake Park', children: [ { key: 21, name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', }, { key: 22, name: 'Joe Black', age: 32, address: 'Sidney No. 3 Lake Park', }, ], }, { key: 3, name: 'Joe Black', age: 32, address: 'Sidney No. 3 Lake Park', children: [ { key: 31, name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', }, { key: 32, name: 'Jim Green', age: 42, address: 'London No. 2 Lake Park', }, ], }, ]; const App = () => { const expandedRowRender = (record) => { const columns = [ { title: 'Name', dataIndex: 'name' }, { title: 'Age', dataIndex: 'age' }, { title: 'Address', dataIndex: 'address' }, ]; const data = record.children; return <Table columns={columns} dataSource={data} pagination={false} />; }; return <Table columns={columns} dataSource={data} expandable={{ expandedRowRender }} />; }; export default App; ``` 在这个示例代码中,我们定义了一个 `expandedRowRender` 函数,在这个函数中,我们使用 Table 组件来渲染子表格。然后,在主表格中,我们将 `expandedRowRender` 函数传递给 `expandable` 属性来实现嵌套表格的效果。具体地,当用户点击主表格中的一个行时,它的子表格就会被展开。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值