vue element中table固定多层表头,拖动表头会被遮盖

vue element中table固定多层表头,百度给的解决办法是给个固定宽度,此时在拖动宽时,宽度依然是固定的,扩大的那部分会溢出,并且不会固定,以下是解决此bug的方法

第一步:在<el-table></el-table>上添加 @header-dragend 这个属性,此属性element中有解释:就是“当拖动表头改变了列的宽度的时候会触发该事件”

<el-table :data="dataList" @header-dragend="changeWidth">

第二步:在需要固定的<el-table-column></el-table-column>列上,添加ref="自定义名字"属性,定义一个死宽度,绑定在列上方,同时子元素的宽的合等于定义的变量宽度,其余属性自己添加,下面只是固定问题的属性

  <el-table-column label="门店" :width="storeWidth" ref="oneStore">
  </el-table-column>

 第三步:在@header-dragend 事件中写代码如下,模仿一下代码即可

  changeWidth() {
        this.storeWidth = 0;
        this.$refs.oneStore.columnConfig.realWidt = 0;
        this.storeWidth=this.$refs.oneStore.columnConfig.children.reduce((p,n)=>{
          return p+n.width*1
        },0)
        this.$refs.oneStore.columnConfig.realWidth = this.storeWidth;

 }

 下面是比较全的小dom例子,自己写的,固定两列,

<template>
  <D2Container class="main-page">


     <el-table :data="dataList"
              @header-dragend="changeWidth" >
         <el-table-column label="门" :width="storeWidth"ref="oneStore">
           <el-table-column label="编1" prop="" width="150" ></el-table-column>
           <el-table-column label="店称2" prop="name" width="150"></el-table-column>
     </el-table-column>

      <el-table-column label="合" :width="totalWidth"  fixed="left" ref="twoTotal">
        <el-table-column label="合计1" prop="" width="100" </el-table-column>
        <el-table-column label="合计2" prop="" width="100"></el-table-column>
        <el-table-column label="合计3" prop=""  width="100"></el-table-column>
     </el-table-column>
    </el-table>
  </D2Container>
</template>

<script>
  export default {
    data () {
      return {
        storeWidth:300,
        totalWidth:300,
      }
    },
    methods: {
      changeWidth() {
        this.storeWidth = 0;
        this.$refs.oneStore.columnConfig.realWidt = 0;
        this.storeWidth=this.$refs.oneStore.columnConfig.children.reduce((p,n)=>{
          return p+n.width*1
        },0)
        this.$refs.oneStore.columnConfig.realWidth = this.storeWidth;

        this.totalWidth=0
        this.$refs.twoTotal.columnConfig.realWidt = 0;
        this.totalWidth=this.$refs.twoTotal.columnConfig.children.reduce((p,n)=>{
          return p+n.width*1
        },0)
        this.$refs.twoTotal.columnConfig.realWidth = this.totalWidth;
      },
      }
</script>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值