基于el-table的动态配置表格列

思路:首先封装JSON文件设置表头信息可以直接写在文件里,通过自定义一个字段控制是否展示。我这里是=2就不展示,0就是展示,使用文件页面遍历数组做为表头数据

  "gasCompanyCol": [
    {
      "prop": "companyIndex",
      "label": "序号",
      "width": "80",
      "formatter": null,
      "align": "center",
      "toolTip": true,
      "noWrap": true,
      "overFlowHidden": true,
      "fixed": true,
      "sfxz":"2"
    },
    {
      "prop": "gsbhData",
      "label": "公司编号",
      "sortable": true,
      "minWidth": "120",
      "formatter": null,
      "align": "center",
      "toolTip": true,
      "showFilter":"gsbh",
      "noWrap": true,
      "overFlowHidden": true,
      "sfxz":"0"
    }]

配合后端拿到当前用户默认展示列信息,遍历接口数据和本地数据做对比,将默认展示的序号以及一些字段添加进去,最后处理好的表头在页面遍历,

// // 获取配置列

const getConfigArrange = async () => {

  const query = {

    lx: '1'

  }

  const res = await _this.$http.get(

    '//interface/Arrange.jsp',

    query

  )

  if (res.length > 0) {

    const newColConfig = []

    const tempObj = {}

    colData.gasCompanyCol.forEach((item, ind) => {

      tempObj[item.prop] = item

      res.forEach((val, index) => {

        if (val.zdm === item.prop) {

          item.sfxz = val.sfxz

          item.id = val.id

          item.pxh = val.pxh

        }

        newColConfig[index] = tempObj[val.zdm]

      })

    })

    const xh = {

      prop: 'companyIndex',

      label: '公司序号',

      width: '80',

      formatter: null,

      align: 'center',

      toolTip: true,

      noWrap: true,

      overFlowHidden: true,

      fixed: true,

      sfxz: '2'

    }

    newColConfig.unshift(xh)

    newList.value = newColConfig

    // console.log(newColConfig)

    return newColConfig

  }

}

 遍历表头

  <template v-for="(item, index) in colList">
        <el-table-column
          :key="index"
          :align="item.align"
          :label="item.label"
          :min-width="item.minWidth"
          :prop="item.prop"
          :sortable="!!item.sortable && sortFlag && 'custom'"
          :width="item.width"
          :fixed="item.fixed"
          :filters="item.showFilter ? toShowFilter(item) : ''"
          :column-key="item.showFilter"
          v-if="item.sfxz === '0' || item.sfxz === '2' || isNoUseConfig"
        >
          <template #default="{ $index, row }">

 通过拖拽改变当前排序位置,保存给后端再刷新表格

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值