VUE+ELEMENTUI表格的表尾合计

 <el-table

                              :data="XXXX"

                              :summary-method="getSummaries"

                              show-summary = "true"

                           >

getSummaries(param) {

        const { columns, data } = param;

        const sums = [];

        columns.forEach((column, index) => {

       

        if (index === 0) {

            sums[index] = '合计';

          }

        else {

            const values = data.map(item => Number(item[column.property]));

            if (!values.every(value => isNaN(value))) {

              sums[index] = values.reduce((prev, curr) => {

                const value = Number(curr);

                if (!isNaN(value)) {

                  return prev + curr;

                } else {

                  return prev;

                }

              }, 0);

            } else {

              sums[index] = 'N/A';

            }

          }

        });

        const totalCol1 = sums[1]; // 第一列的合计总数

        const totalCol2 = sums[2]; // 第二列的合计总数

        const totalCol4 = sums[4]; // 第4列的合计总数

        const totalCol5 = sums[5]; // 第5列的合计总数

        if (!isNaN(totalCol2) && !isNaN(totalCol1) && totalCol1 !== 0) {

            sums[3] = ((totalCol2 / totalCol1)* 100).toFixed(2) +"%"; // 计算第三列的值,并保留两位小数

          } else {

            sums[3] = 'N/A'; // 如果无法计算,则显示'N/A'

          }

        if (!isNaN(totalCol5) && !isNaN(totalCol4) && totalCol4 !== 0) {

            sums[6] = ((totalCol5 / totalCol4)*100).toFixed(2)+"%"; // 计算第三列的值,并保留两位小数

          } else {

            sums[6] = 'N/A'; // 如果无法计算,则显示'N/A'

        }

         

         return sums;

    },

相关推荐

  1. 头插,插,逆序 and 合并两个有序

    2024-07-12 20:52:02       34 阅读
  2. 单链

    2024-07-12 20:52:02       57 阅读
  3. 【数据结构】单链插法

    2024-07-12 20:52:02       33 阅读
  4. 到头打印(递归)

    2024-07-12 20:52:02       28 阅读
  5. Vue3-admin-template表格合计计算

    2024-07-12 20:52:02       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 20:52:02       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 20:52:02       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 20:52:02       57 阅读
  4. Python语言-面向对象

    2024-07-12 20:52:02       68 阅读

热门阅读

  1. 简单有效防止CDN被盗刷流量

    2024-07-12 20:52:02       18 阅读
  2. Linux 命令个人学习笔记

    2024-07-12 20:52:02       18 阅读
  3. SpringBoot实现Read Through模式

    2024-07-12 20:52:02       20 阅读
  4. linux中vim切换输入中文

    2024-07-12 20:52:02       17 阅读
  5. 模型剪枝知识点整理

    2024-07-12 20:52:02       21 阅读
  6. 雅思词汇及发音积累 2024.7.12

    2024-07-12 20:52:02       23 阅读
  7. php上传文件

    2024-07-12 20:52:02       17 阅读
  8. linux kernel ptr dump

    2024-07-12 20:52:02       19 阅读