zoukankan      html  css  js  c++  java
  • element自定义合计列

    el-table 添加属性

          <el-table  
                show-summary              
                :summary-method="summaryMethod">
                ...
          </el-table>
           ...    
          // 添加方法
          methods:{
          summaryMethod(param) {
          const { columns, data } = param;
          const sums = [];
          columns.forEach((column, index) => {
            if (index === 0) {
              sums[index] = "合计"; // 名称定义
              return;
            }
            const values = data.map((item) => Number(item[column.property]));
            if (!values.every((value) => isNaN(value))) {
              if (column.property == "score" || column.property == "scoreNum") {
                // 需要自定义添加的列属性名称
                sums[index] = values.reduce((prev, curr) => {
                  const value = Number(curr);
                  if (!isNaN(value)) {
                    return prev + curr;
                  } else {
                    return prev;
                  }
                }, 0);
                sums[index] += "";   // 数据显示处理
              }
            } else {
                // 不需要显示的属性,显示空,也可以自定义 --  
          }
          });
          return sums;
        },
       }
    
    愿以往所学皆有所获
  • 相关阅读:
    卡特兰数
    割点和桥
    子序列(超级水)
    react 进行时
    又开启react之路
    关于特殊字体
    react 组件传值
    git 的安装和项目建立
    ES6 let and const
    js封装的一行半显示省略号(字数自由控制)
  • 原文地址:https://www.cnblogs.com/Azune/p/14329355.html
Copyright © 2011-2022 走看看