vue3 ts table合计样式更改

table合计代码


          <el-table
            show-summary
            :summary-method="summary"
            :cell-style="cellStyle"
          >
         </el-table>
         

// 引入   ,因为返回不能是VNode,所以需要引入h函数
import {h} from "vue";


// 方法  (计算和官方写法一致),除了返回的时候有区分
    function summary(param: any) {
      const { columns, data } = param;

      const sums = [] as any ;
      columns.forEach((column: any, index: any) => {
        if (index === 0) {
          sums[index] = `合计(${
            state.baseInfoForPort.exchange == "CN"
              ? "元"
              : state.baseInfoForPort.exchange == "HK"
              ? "港币"
             : "美元"
         }`;
        return;
        }
        const values = data.map((item: any) => Number(item[column.property]));
        // 针对某列做合计
        if (
          column.property == "preMarketValue" ||
          column.property == "finalMarketValue"
        ) {
          if (!values.every((value: any) => Number.isNaN(value))) {
            sums[index] = `${values.reduce((prev: any, curr: any) => {
              const value = Number(curr);
              if (!Number.isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0)}`;
          }
          // 样式更改在这里, 负数显示绿色,正数显示红色
          if(Number(sums[index])>0){
          sums[index] = h('span',{style:'color:#f56c6c'},format(Number(Number(sums[index]).toFixed(2))))
          }else
          sums[index] = h('span',{style:'color:#19BE3C'},format(Number(Number(sums[index]).toFixed(2))))
        } else {
          sums[index] = " ";
        }
      });

      return sums;
    }
 `

相关推荐

  1. vue3 ts table合计样式更改

    2024-04-28 20:48:02       10 阅读
  2. VueVue3.0样式隔离

    2024-04-28 20:48:02       37 阅读
  3. vue3-类与样式绑定

    2024-04-28 20:48:02       27 阅读
  4. 10 在Vue3中使用SCSS编写样式

    2024-04-28 20:48:02       30 阅读
  5. vue3中集成sass实现全局scss样式变量

    2024-04-28 20:48:02       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-28 20:48:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-28 20:48:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-28 20:48:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-28 20:48:02       18 阅读

热门阅读

  1. MySQL详细步骤及案列

    2024-04-28 20:48:02       12 阅读
  2. maya 设置半径 获取时长,设置时长

    2024-04-28 20:48:02       11 阅读
  3. react写一个从下往上划出的弹框弹窗组件

    2024-04-28 20:48:02       9 阅读
  4. redis 键常用命令

    2024-04-28 20:48:02       11 阅读
  5. AI作画算法原理详解

    2024-04-28 20:48:02       10 阅读
  6. [GN] 车300笔试记

    2024-04-28 20:48:02       10 阅读
  7. Linux制作docker镜像

    2024-04-28 20:48:02       12 阅读
  8. 前端初学者必读的 Web Workers指南

    2024-04-28 20:48:02       11 阅读