antd table长表格如何出现滚动条


如图想实现如上图所示,看antd table官方文档想实现这个,介绍的很不详细,实现起来一堆坑。
阿里云页面的这种表格,拉伸起来也有很多bug,也不知道他的实现方法如何,我这边介绍一种方法实现如下,遇到拉伸也不怕…

    <div class="content">
      <a-table
        :columns="columns"
        :data-source="dataSource"
        :row-key="record => record.id"
        :pagination="pagination"
        :scroll="{ x: '1400px' | true }"
        class="charge-table"
        @change="handleTableChange"
      >
        <div slot="trialQuota" slot-scope="text">{{ text }}小时</div>
        <template slot="action" slot-scope="text, record">
          <a-button type="link" style="margin-left: -8px" @click="openDetail(text, record)"> 详情 </a-button>
          <a-button type="link" @click="openCharge(text)"> 充账 </a-button>
          <a-button type="link" :disabled="text.tryData" @click="onTry(text)"> 试用 </a-button>
        </template>
      </a-table>
    </div>
  .content {
    flex: 1;
    background: #ffffff;
    border-radius: 8px;
    padding: 0 20px;
    position: relative;
  }
   /deep/.ant-spin-nested-loading {
    position: absolute;
    left: 20px;
    right: 20px;
  }

重点在于css设置绝对定位,columns每一项都要设置width,且width必须为固定px,不能是百分比(%),不然拉伸会被隐藏,至于单元格里面是否折行无所谓,刚开始就是在这里踩了很多坑

const columns = [
  {
    title: '编号',
    dataIndex: 'id',
    // width: '3.4%',
    width: '58px'
  },
  {
    title: '用户平台名',
    dataIndex: 'ourUserName',
    // width: '6.9%',
    width: '173px'
  },
  {
    title: '用户外部名',
    dataIndex: 'userName',
    // scopedSlots: { customRender: 'userName' },
    //  width: '166px'
    // width: '6.9%',
    width: '145px',
    ellipsis: true
  },
  {
    title: '用户组',
    dataIndex: 'groupDesc',
    // scopedSlots: { customRender: 'groupDesc' },
    // width: '10%',
    ellipsis: true,
    width: '198px'
  },
  {
    title: '用户组账户',
    dataIndex: 'groupName',
    // width: '8.4%',
    width: '145px'
  },
  {
    title: '余额(单位:核时)',
    dataIndex: 'corestimeBalance',
    // width: '7.9%',
    width: '129px'
  },
  {
    title: 'VPN地址',
    dataIndex: 'vpnAddress',
    scopedSlots: { customRender: 'vpnAddress' },
    // width: '13.2%',
    width: '217px'
    // ellipsis: true,
    // width: '246px'
    // customCell: () => {
    //   return {
    //     style: {
    //        'min-width': '300px',
    //       'white-space': 'nowrap',
    //       'text-overflow': 'ellipsis'
    //     }
    //   }
    // }

    //    customCell: () => {
    //   return {
    //     style: {
    //         'color':'yellow',
    //       'width': '246px'
    //     }
    //   }
    // },
    //    customHeaderCell: () => {
    //   return {
    //     style: {
    //         'color':'yellow',
    //       'width': '246px'
    //     }
    //   }
    // }
  },
  {
    title: 'SSH地址',
    dataIndex: 'sshAddress',
    ellipsis: true,
    // width: '13.2%',
    width: '245px'
  },
  {
    title: '试用方式',
    dataIndex: 'trialMethod',
    ellipsis: true,
    // width: '7.8%',
    width: '128px'
  },
  {
    title: '试用额度',
    dataIndex: 'trialQuota',
    // width: '6.9%',
    width: '104px',
    scopedSlots: { customRender: 'trialQuota' }
  },
  {
    title: '集群操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
    fixed: 'right',
    width: '132px'
  }
]

实现出来的效果如下:
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值