当前位置:   article > 正文

el-table 合集行合并_el-tabel 合计行合并

el-tabel 合计行合并

1.模板中

  1. <el-table :data="form.guestList1" show-summary :summary-method="getSummaries" :span-method="arraySpanMethod" ref="tableSumRef1">
  2. <el-table-column label="姓名" prop="name" align="center">
  3. </el-table-column>
  4. <el-table-column label="国籍" align="center" prop="nationality">
  5. </el-table-column>
  6. <el-table-column label="总片酬(万元)" align="center" prop="totalRemuneration">
  7. </el-table-column>
  8. <el-table-column label="参与期数" align="center" prop="participation">
  9. </el-table-column>
  10. </el-table>

2.js中

   2.1计算合计

  1. /** 计算合计*/
  2. getSummaries(param) {
  3. const {
  4. columns,
  5. data
  6. } = param;
  7. const sums = [];
  8. columns.forEach((column, index) => {
  9. const values = data.map(item => Number(item[column.property]))
  10. if (index === 2) {
  11. sums[index] = values.reduce((prev, curr) => {
  12. const value = Number(curr)
  13. if (!isNaN(value)) {
  14. return prev + curr
  15. } else {
  16. return prev
  17. }
  18. }, 0)
  19. sums[index] = "合计:" + sums[index] + " 万元"
  20. }
  21. })
  22. return sums
  23. },

2.2合并最后一行

  1. arraySpanMethod() {
  2. setTimeout(() => {
  3. if (this.$refs.tableSumRef1) {
  4. let current = this.$refs.tableSumRef1.$el
  5. .querySelector(".el-table__footer-wrapper")
  6. .querySelector(".el-table__footer");
  7. let cell = current.rows[0].cells;
  8. cell[0].style.display = "none";
  9. cell[1].style.display = "none";
  10. cell[2].colSpan = "4";
  11. }
  12. }, 50);
  13. },

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/686725
推荐阅读
相关标签
  

闽ICP备14008679号