antd table长表格出现滚动条的操作方法

Aine ·
更新时间:2024-09-20
· 1618 次阅读

如图想实现如上图所示,看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' } ]

实现出来的效果如下:

到此这篇关于antd table长表格出现滚动条的操作方法的文章就介绍到这了,更多相关antd table长表格滚动条内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!



antd 表格 方法 滚动条 table

需要 登录 后方可回复, 如果你还没有账号请 注册新账号