antd table minHeight

网上常见设置antd table最小宽度的方案:
antd table minHeight
这种方法也不是不可以,但是若需要动态设置最小高度的话,这样写就不是很合适。

所以选择了动态计算table高度的方法来实现:

第一步:计算table scroll height

const extraHeight = 20; // table距离底部的距离
const tableMinHeight = 300 // table的最小高度
const getTableHeight = () => {
    const tHeader = document.querySelector('.ant-table-thead');
    // 表格内容距离顶部的距离
    let tHeaderBottom = 0;
    if (tHeader) {
      tHeaderBottom = tHeader.getBoundingClientRect().bottom;
    }
    // 计算剩余的高度
    const innerHeight = window?.innerHeight ?? 0;
    const calcHeight =  tHeaderBottom + extraHeight;
    // 如果最小高度 > 剩余的高度,则使用最小高度,反之使用剩余的高度
    return tableMinHeight && tableMinHeight > innerHeight - calcHeight ? tableMinHeight : `calc(100vh - ${calcHeight}px)`;
  };

第二步:设置滚动区域的高

const tableHeight = getTableHeight();
<Table
  ...
  scroll={{y: tableHeight}}
  ...
/>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值