关于使用 ant-design-vue a-table 超出部分 隐藏并显示省略号

如果只是对于超出隐藏 可以直接使用  ellipsis 进行设置,方便快捷

columns = [
{
  id: "1",
  checked:true,
  width: 100,
  title: '更新时间',
  dataIndex: 'update_at',
  ellipsis: true,
}

]

但有的时候 title的hover显示效果 满足不了我们的 需求 , 要求我们使用类似于tooltip的形式  对省略的字段进行显示   代码如下:

columns = [
{
  id: "1",
  checked:true,
  width: 100,
  title: '更新时间',
  dataIndex: 'update_at',
  customCell  : () => {
    return {
      style: {
         width: '100px',
         overflow: 'hidden',
         whiteSpace: 'nowrap',
         textOverflow:'ellipsis',
         cursor:'pointer'
       }
    }
   },
   customRender: (text,record) => <a-tooltip placement="topLeft" title = {record.create_at} >{record.create_at}</a-tooltip>
}

]

但是对于某些列表项,设置 fixed后,发现直接使用   ellipsis: true,  已经不起作用了,代码如下:

{
  id: "1",
  checked:true,
  title: '账单编号',
  dataIndex: 'bill_number',
  width: 120,
  fixed: 'left',
  customRender: (text) => <span class="col-sql" title= {text}>{text}</span>,
}

自定义渲染内容,并且设置class样式,尤其注意的是,样式必须添加宽度,原因有可能是:ant的tb的display为table-cell,可能是导致white-space:nowrap宽度失效的原因。所以这里需要设置一个宽度定值。

overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: inline-block;
width: 100px; 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值