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);
    },
相关推荐
px不是xp16 小时前
DeepSeek API集成:让小程序拥有AI大脑
javascript·人工智能·小程序
前端那点事16 小时前
Vue插槽用法全解析(Vue2+Vue3适配)| 组件复用必备
vue.js
Ruihong16 小时前
Vue v-on 在 React 中 VuReact 会如何实现?
vue.js·react.js·面试
|晴 天|17 小时前
实现草稿自动保存功能:5秒无操作自动保存
前端·vue.js·typescript
小汪说干货17 小时前
2026年4月最新|公众号文章插入文档附件3种技术方案
javascript·小程序
qq_120840937117 小时前
Three.js 骨骼动画工程实战:AnimationMixer、剪辑与混合权重调参
开发语言·javascript·ecmascript
早起傻一天~G19 小时前
vue2+element-UI上传图片封装
开发语言·javascript·ui
广师大-Wzx19 小时前
JavaWeb:前端部分
java·前端·javascript·css·vue.js·前端框架·html
M ? A19 小时前
你的 Vue v-memo 与 v-once,VuReact 会编译成什么样的 React 代码?
前端·javascript·vue.js·经验分享·react.js·面试·vureact
吴声子夜歌19 小时前
Vue3——过度和动画效果
前端·vue.js·es6