Antd Table表头加Icon和气泡提示的坑

对于Antd Table组件的columns数组来说,它需要接受2个属性(filterDropdown,filterIcon)才能在表头某个属性旁展示图标Icon:

columns: [{

          title: '表达式', dataIndex: 'formulaTenderAmount', key: 'formulaTenderAmount', width: 150, placeholder: '请输入表达式',

          filterDropdown: (<div></div>),

          filterIcon: <Tooltip placement="top" title="气泡悬浮提示文本" >

            <Icon type='question-circle-o' style={{ marginLeft: 1 }} />

          </Tooltip>,

        },{

          title: '操作',

          dataIndex: 'operation',

          key: 'operation',

          width: 305,

          fixed: 'right',

        },
],

 

然后,结果是怎样呢?

结果是气泡提示框的文本并不是我们期望的 “气泡悬浮提示文本” ,而是 “筛选” 两个字

 

为什么?

我查了一下,有位简书的作者给出了答案:https://www.jianshu.com/p/b67ca05cf380

如此,我改成了以下的代码,并且新增了onVisibleChange方法,新增了state的属性filterTitleKey,并且在Table组件属性中增加了locale对象:

this.state = {

      filterTitleKey: '',

}
columns: [{

          title: '表达式', dataIndex: 'formulaTenderAmount', key: 'formulaTenderAmount', width: 150, placeholder: '请输入表达式',

          filterDropdown: (<div></div>),

          filterIcon: <Tooltip onVisibleChange={() => this.onVisibleChange(1)} placement="top" >

            <Icon type='question-circle-o' style={{ marginLeft: 1 }} />

          </Tooltip>,

        },{

          title: '操作',

          dataIndex: 'operation',

          key: 'operation',

          width: 305,

          fixed: 'right',

        },

],
onVisibleChange = (key) => { //Tooltip 显示隐藏的回调,类似onmouseenter 进入离开事件,用来显示我们不同的信息提醒

    let str = '';

    switch (key) {

      case 1:

        str = '函数计算,x表示发行规模';

      default:

        break;

    }

    this.setState({

      filterTitleKey: str,

    });

  }

 

这边会有Table的一个属性locate,官网是这样解释的:

 

<Table

            loading={loading}

            className='editableTable'

            size="small"

            style={{ height: tableHeight - 40 }}

            columns={columns}

            locale={{

              filterTitle: filterTitleKey || '默认', // 设一个默认是防止控制台的报错,移除以后造成filterTitle为空,失败;

            }}

            dataSource={dataSource}

            pagination={pagination}

            scroll={{ x: 2400, y: tableScrollHeight }}

/>

 

这样就能正常的显示气泡文本了:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hzxOnlineOk

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值