el-table 合集行合并

1.模板中

复制代码
              <el-table :data="form.guestList1" show-summary :summary-method="getSummaries" :span-method="arraySpanMethod" ref="tableSumRef1">
                <el-table-column label="姓名" prop="name" align="center">
                </el-table-column>
                <el-table-column label="国籍" align="center" prop="nationality">
                </el-table-column>
                <el-table-column label="总片酬(万元)" align="center" prop="totalRemuneration">
                </el-table-column>
                <el-table-column label="参与期数" align="center" prop="participation">
                </el-table-column>
              </el-table>

2.js中

2.1计算合计

复制代码
    /**  计算合计*/
    getSummaries(param) {
      const {
        columns,
        data
      } = param;
      const sums = [];
      columns.forEach((column, index) => {
        const values = data.map(item => Number(item[column.property]))
        if (index === 2) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          sums[index] = "合计:" + sums[index] + " 万元"
        }
      })
      return sums
    },

2.2合并最后一行

复制代码
    arraySpanMethod() {
      setTimeout(() => {
        if (this.$refs.tableSumRef1) {
          let current = this.$refs.tableSumRef1.$el
            .querySelector(".el-table__footer-wrapper")
            .querySelector(".el-table__footer");
          let cell = current.rows[0].cells;

          cell[0].style.display = "none";
          cell[1].style.display = "none";
          cell[2].colSpan = "4";
        }
      }, 50);
    },
相关推荐
Z小明5 小时前
第 6 章 组件进阶
前端·vue.js
默_笙6 小时前
🚋 从流水线到地铁网:为什么复杂 AI 都要拆成多 Agent(上)——LangGraph 基础入门
前端·javascript
ID34610744207 小时前
【课程设计】基于Spring Boot+Vue的游戏账号租赁系统的设计与实现-计算机毕设 附源码50345
javascript·vue.js·spring boot·python·node.js·php·课程设计
柚yuzumi7 小时前
彻底搞懂 JavaScript 类型转换:显式转换、隐式转换与 ToPrimitive
前端·javascript·node.js
AI情绪识别开源8 小时前
检信ALLEMOTION 认知评估分析器 · WebSocket 推送数据文档
javascript
OpsEye9 小时前
公司内部全员使用 AI,如何保证会话合规、行为可审计?
javascript·ai编程
变与不变8069 小时前
JS事件机制精讲
前端·javascript
沉迷...10 小时前
Git skip-worktree 使用笔记(本地忽略配置文件)
javascript·git
FYKJ_201010 小时前
【毕设分享】基于Web的校园兼职信息发布与申请系统07059
前端·vue.js·spring boot·mysql·typescript·spark·课程设计