el-table 合计

 

 

 

   <el-table
          ref="pageTable"
          :data="tableData"
          border
          style="width: 100%"
          :summary-method="getSummaries"
          show-summary
        >

  

  getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 1) {
          sums[index] = "合计";
        } else {
          if (index === 3) {
            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";
            }
          }
        }
      });
      return sums;
    },

  

posted @ 2024-11-20 17:47  ThisCall  阅读(2)  评论(0编辑  收藏  举报