VUE-element设置动态表格,从列转行

就一下代码块里面有注解了。。可以参考一下

主要是,你表格的表头是动态的,然后设置多少列,然后取你动态表头的数据,转换成map,取到你的中文,关联的数组下标。一一对应就可以弄成动态了!而且还是动态的宽度。可以达到俩列的长度,一个表头的值,然后可以拿第二个table做数据填充,不说了看图就行了,大家也是见过世面的!

 <el-table
      ref="one"
      border
      :data="[productWidth]"
      :fit="false"
      :header-cell-style="{borderTop : '2px solid #dfe6ec',borderLeft : '2px solid #dfe6ec',textAlign: 'center'}"
      style="font-size: 12pt; "
    >
      <el-table-column align="center" :width="item.dataHeaderWidth" v-for="item in dataHeader" :key="item.prop":prop="item.prop":label="item.label">
      </el-table-column>

    </el-table>

为啥下列还要for循环添加一个列属性呢,因为第一列通常要有说明啥的,所以可以加一个说明达到效果

 detectionCon(){
        //检测表的查询条件
        detectionConditionsList(this.queryParamsForm1).then(response => {
          this.from3 = response.rows;
        });
        detectionBaseMetalList(this.queryParamsForm1).then(response => {
          /* console.log(JSON.stringify(response.rows));*/
          this.from1 = response.rows;

          if(this.from1 == []){
            alert("此母材已被完全加工!");
            return;
          }

          ///这里是设置动态表格多少列
          this.from2Size = this.from1[this.from1.length-1].frontEndNumber;


          //这里是设置动态表格,从列转行
          this.temp = new Array(this.from1.length).fill('').map((_, index) => 'col' + index)
          let orderab = this.from1.map(item => item.orderabSign)
          let clientName = this.from1.map(item => item.clientName)
          let numberSlit = this.from1.map(item => item.numberSlit)
          this.dataHeader = this.temp.map((item, index) => ({
            prop: item,

            label: clientName[index]+(orderab[index] != null && orderab[index] !='' ?"("+orderab[index]+")":'') ,
            dataHeaderWidth:  numberSlit[index]*80 + "px;"
          }))
          this.dataHeader.unshift({prop: 'clientName', label: '客户',dataHeaderWidth:  2*80 + "px;"
          })

          //这里是设置表格内容
          for (let i in this.from1) {
            /* console.log(JSON.stringify(i ));*/
            if(i == 0){
              this.productWidth['clientName'
                ] = '成品宽度'
            }
            this.productWidth['col' + i
              ] = this.from1[i
              ].productWidth
          }
          //设置表格长度
          for (let i in this.from1) {
            if(i == 0){
              this.dataHeaderWidth['clientName'
                ] =  2*80 + "px;"
            }
            //"'width:' + percent + '%'"
            this.dataHeaderWidth['col' + i
              ] =   this.from1[i].numberSlit*80 + "px"

          }
          this.$forceUpdate();

          /* console.log(JSON.stringify(this.dataHeaderWidth ));
           console.log(JSON.stringify(this.productWidth ));
           console.log(JSON.stringify(this.dataHeader ));*/
        });
      }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值