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);
    },
相关推荐
脑袋大大的3 小时前
JavaScript 性能优化实战:减少 DOM 操作引发的重排与重绘
开发语言·javascript·性能优化
速易达网络4 小时前
RuoYi、Vue CLI 和 uni-app 结合构建跨端全家桶方案
javascript·vue.js·低代码
耶啵奶膘4 小时前
uniapp+firstUI——上传视频组件fui-upload-video
前端·javascript·uni-app
JoJo_Way4 小时前
LeetCode三数之和-js题解
javascript·算法·leetcode
视频砖家5 小时前
移动端Html5播放器按钮变小的问题解决方法
前端·javascript·viewport功能
lyj1689975 小时前
vue-i18n+vscode+vue 多语言使用
前端·vue.js·vscode
GISer_Jing8 小时前
Monorepo+Pnpm+Turborepo
前端·javascript·ecmascript
天涯学馆8 小时前
前端开发也能用 WebAssembly?这些场景超实用!
前端·javascript·面试
我在北京coding9 小时前
TypeError: Cannot read properties of undefined (reading ‘queryComponents‘)
前端·javascript·vue.js