vxeTable反转表格

文章目录


前言

如果遇到列为动态值,行相对固定的情况,这种时候就需要用到行列反转,这里我以vxeTable表格为例。

在这里插入图片描述

直接上代码

        <vxe-grid
          ref="tableRefRight"
          :auto-resize="true"
          :columns="dataColumn"
          :data="tableData"
          :loading="rightTableLoading"
          :print-config="{}"
          :show-header="true"
          :sync-resize="true"
          border
          height="auto"
          resizable
        >
        </vxe-grid>

created 钩子 核心代码

    reverseTable(table, type) {
      let name = "";
      if (type === 1) {
        name = "nickName";
      } else if (type === 2) {
        name = "productName";
      } else if (type === 3) {
        name = "scenarioName";
      }
      // 构建初始化表格数据
      // 表体参数
      const buildData = this.originalTitle.map((col) => {
        const item = { col0: col[name], timeId: col.timeId };
        table.forEach((row, index) => {
          item[`col${index + 1}`] = { ...row };
          item[`col${index + 1}`].isLoading = false;
          item[`col${index + 1}`].newTag = null;
        });
        return item;
      });
      // 表头渲染参数
      let buildColumns = [
        {
          field: "col0",
          width: 150,
          fixed: "left",
          align: "center",
          title: "预排时间",
        },
      ];
      table.forEach((item, index) => {
        buildColumns.push({
          field: `col${index + 1}`,
          width: 170,
          staffId: item.staffId,
          align: "center",
          title: item[name],
          slots: { default: `tag` },
        });
      });
      this.tableData = buildData;
      this.dataColumn = buildColumns;
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骆骆爱学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值