react+antd动态设置table最大滚动高度

场景,无论页面中添加多少元素,始终让table的高度自适应,这样在table设置了最大高度的情况,页面不用再出现多条滚动条。

  // 计算table最大高度
export function getTableMaxH (tableEl,callback) {
    var paginationH=24+32 //24是页码的高度 32是页码上下的边距,这里直接写死,也可进行js获取
    const setH=()=>{
      const appMainBox=document.querySelector('#appMainBox').getBoundingClientRect()
      const table=document.querySelector(tableEl).getBoundingClientRect()
      const res=appMainBox.height-table.top-paginationH
    //   console.log('paginationH',appMainBox.height,table.height,paginationH,res)
      callback(res)
    }
    setH()
    window.onresize=function(){
      setH()
    }
  }
this.state = {
            TableMaxH:300 //默认
        }
// 使用
 componentDidMount() {
        this.fetchTableData();
        getTableMaxH('#table',res=>{
            this.setState({
                TableMaxH:res
            })
        })
    }
<Table columns={columns} scroll={{ y:this.state.TableMaxH}} />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值