vxe-动态计算表格列宽度

文章讲述了在开发中如何根据用户选择的复选框数量和文字描述动态计算表格列宽,提供了一个calculateWidth函数示例,根据不同类型的列(如radio、checkbox、state等)来确定合适的宽度。
摘要由CSDN通过智能技术生成

1.场景

        在实际开发中,根据用户需要或者自定义表格编辑功能组件时候,就需要根据用户自定义选择的复选框数量,文字描述信息来进行动态的计算给对应的表格列进行计算对应的列宽并进行赋值。

2.代码

对应新列

NewColumn(column) {
          const newColumn = {
              title: column.label,
              align: 'center',
              width: this.calculateWidth(column),
              dataType: column.type,
              options: column.options.options,
          };
          this.dynamicColumns.push(newColumn)
      },

动态计算表格

        //   动态计算表头宽度
        calculateWidth(column){
            // 对应同类型列进行判断计算
        if(column.type=='radio'||column.type=='checkbox'||column.type=='state'){
            let arr =column.options.options;
            let optionNumber=arr.length;
            let labelString=''
            for(let i = 0; i < optionNumber; i++){
                // 累加计算,单列中文字内容所在个数
                labelString+= arr[i].label;
            }
            let labelNumber= labelString.length;
            // 对应的列宽=边距+字数*字宽+复选框个数*宽度
            let allWidth =optionNumber*(19+7)+labelNumber*16
            return allWidth
        }
        if(column.type=='switch'||column.type=='uploadFileAll'){
            return '100'
        }
        else{
            return '200'
        }
    },

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值