Element实现二维展开列表(嵌套表)

由于用户访问日志统计数据项内容较多,需要对数据项进行分级显示,便于直观查看;接口获取的数据项都保存在一个list内,前端对数据拆分处理实现展开显示子表效果。

效果图如下:
在这里插入图片描述

  • 实现思路:使用el-table的type=”expand“属性,接口请求获取的list父表,子表的字段值保存在一起,method对请求获取的list进行拆分,子表字段值保存在tableData的childRowData中,在el-table绑定的list数据中增加childRowData对象保存嵌套表list,template内置插槽slot使用el-table显示子表
    代码如下:
<!--  html部分 -->
 <el-table
        style="width: 100%"
        ref="table"
        :data="tableData"
        tooltip-effect="dark"
        highlight-parcelItem-row
        border
        :height="tableHeight"
        show-overflow-tooltip
        stripe
        :header-cell-style="{ background: '#dcdfe6' }"
      >
      <!--子表实现 -->
        <el-table-column type="expand">
          <template v-slot="slot">
            <el-table  :data="slot.row.childRowData" style="width: 90%" ref="table" :header-cell-style="{ background: '#dcdfe6' }" >
              <el-table-column label="" prop="tagName"></el-table-column>
              <el-table-column label="访问量" prop="pvCount"></el-table-column>
              <el-table-column label="访问人数" prop="uvCount"></el-table-column>
              <el-table-column label="新增用户数" prop="newaddCount"></el-table-column>
              <el-table-column label="会员升级数" prop="upgradeCount"></el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column label="访问日期" prop="dailyDate"></el-table-column>
        <el-table-column label="访问总量" prop="pvCount"></el-table-column>
        <el-table-column
          label="游客访问量"
          prop="pvCountTourist"
        ></el-table-column>
        <el-table-column label="总访问人数" prop="uvCount"></el-table-column>
        <el-table-column
          label="游客访问人数"
          prop="uvCountTourist"
        ></el-table-column>
        <el-table-column
          label="新增访问人数"
          prop="newaddCount"
        ></el-table-column>
        <el-table-column
          label="新增游客访问人数"
          prop="newaddCountTourist"
        ></el-table-column>
        <el-table-column
          label="会员升级总数"
          prop="upgradeCount"
        ></el-table-column>
      </el-table>

methods处理方法代码:

search() {
      statApi.listStatIndex(this.filterData, this.pageInfo, {
        success: (data) => {
          this.tableData = data.result;
          this.expandRow = [];
          this.tableData.forEach((item,index) => {
            this.expandRow = [];
            const childRowData1 = {};
            childRowData1.tagName = "V1";
            childRowData1.pvCount = item.pvCountV1;
            childRowData1.uvCount = item.uvCountV1;
            childRowData1.newaddCount = item.newaddCountV1;
            childRowData1.upgradeCount = item.countToV1;
            this.expandRow.push(childRowData1);
            const childRowData2 = {};
            childRowData2.tagName = "V2";
            childRowData2.pvCount = item.pvCountV2;
            childRowData2.uvCount = item.uvCountV2;
            childRowData2.newaddCount = item.newaddCountV2;
            childRowData2.upgradeCount = item.countToV2;
            this.expandRow.push(childRowData2);
            const childRowData3 = {};
            childRowData3.tagName = "V3";
            childRowData3.pvCount = item.pvCountV3;
            childRowData3.uvCount = item.uvCountV3;
            childRowData3.newaddCount = item.newaddCountV3;
            childRowData3.upgradeCount = item.countToV3;
            this.expandRow.push(childRowData3);
            this.tableData[index].childRowData = this.expandRow;
          });
          this.pageInfo.totalElements = data.page.totalElements;
        },
        fail: (data) => {
          this.$notify({
            title: "错误",
            message: data.msg,
            type: "error",
          });
        },
      });
    },
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值